<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT">










<meta property="og:type" content="website">
<meta property="og:title" content="苏生不惑的博客">
<meta property="og:url" content="http://yoursite.com/page/24/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="苏生不惑的博客">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/page/24/">



<meta name="referrer" content="never"> ​​​​


  <title>苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/12/09/如何清除手机拍照的图片-exif-防止泄露你的隐私/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/12/09/如何清除手机拍照的图片-exif-防止泄露你的隐私/" itemprop="url">如何清除手机拍照的图片 exif 防止泄露你的隐私</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-09T20:27:57+08:00">
                2019-12-09
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.3k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  8 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>这两天有个微博话题 #微信发原图可泄露位置信息# </p>
<blockquote>
<p>网传用微信发送照片原图，会泄露位置信息。专家表示确实如此，不过需同时满足3个条件：①手机GPS定位已打开；②拍照设置保存了地理位置；③发送原图。</p>
</blockquote>
<p>然后【腾讯微信团队】对此回应：无论用微信、邮件或是其他传输工具发原图，都会附带位置、时间、拍摄机型等Exif信息。但朋友圈发的照片都经过系统自动压缩，不带位置等信息。若担心，可关闭定位或P图再发<a href="https://weibo.com/1930378853/IiLlCpuJW?refer_flag=1001030103" target="_blank" rel="noopener">https://weibo.com/1930378853/IiLlCpuJW?refer_flag=1001030103</a>_<br><img src="https://upload-images.jianshu.io/upload_images/17817191-fa6ac52cedb439a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="exif"><a href="#exif" class="headerlink" title="exif"></a>exif</h3><p>这里说的exif是什么呢？</p>
<blockquote>
<p>可交换图像文件格式（英语：Exchangeable image file format，官方简称Exif），是专门为数码相机的照片设定的，可以记录数码照片的属性信息和拍摄数据。</p>
</blockquote>
<blockquote>
<p>Exif可以附加于JPEG、TIFF、RIFF等文件之中，为其增加有关数码相机拍摄信息的内容和索引图或图像处理软件的版本信息。<br>Windows 7操作系统具备对Exif的原生支持，通过鼠标右键点击图片打开菜单，点击属性并切换到详细信息标签下即可直接查看Exif信息。<br>Exif信息是可以被任意编辑的，因此只有参考的功能。</p>
</blockquote>
<p>以上来自维基百科 <a href="https://zh.wikipedia.org/wiki/EXIF" target="_blank" rel="noopener">https://zh.wikipedia.org/wiki/EXIF</a></p>
<p>只有使用设备（如相机、手机、摄像头等）拍摄的照片才有 EXIF 数据（截图没有），可以获取到拍照方向、相机设备型号、拍摄时间、ISO 感光度、GPS 地理位置等数据 ，简单地说，exif=jpeg+拍摄参数。 </p>
<p>比如我之前在公司用手机拍的这张图片。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-e37311b7aa776392.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="exif属性"><a href="#exif属性" class="headerlink" title="exif属性"></a>exif属性</h3><p>在Windows上右键图片可以看到详细信息，包含相机型号，焦距，拍摄日期等。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-bcf1a43d866f20a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-ea4743ef226833c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>还有经纬度<br><img src="https://upload-images.jianshu.io/upload_images/17817191-1648c973cbdfccf5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>当然也可以使用专业的magicexif 来看  <a href="http://www.magicexif.com/" target="_blank" rel="noopener">http://www.magicexif.com/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-0df03e7fc92d7fc3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2156e4c6829545a2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>也可以使用一些在线工具查看exif，比如 <a href="https://yijiangaitu.com/exif" target="_blank" rel="noopener">https://yijiangaitu.com/exif</a> 但不知道这些工具是否会将你的原图保存在他们服务器，是个隐患，不过有个方法可以简单测试下是否上传了原图：断开网络，如果仍能正常使用说明不是后端程序处理，原图没有上传。</p>
<p>所以还是推荐使用开源的，比如<br> <a href="https://github.com/FeeiCN/EXIF" target="_blank" rel="noopener">https://github.com/FeeiCN/EXIF</a> ，我用这个搭建了个在线查看exif工具<a href="http://122.51.155.172:5000/" target="_blank" rel="noopener">http://122.51.155.172:5000/</a>  ，上传图片后获取的信息如下：<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f833838b35f9cdd0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>然后在谷歌地图输入经纬度  40.0419444444,116.279166667  可以定位到新浪的位置（我在公司拍的）。<br><a href="https://www.google.com/maps/place/40%C2%B002&#39;31.0%22N+116%C2%B016&#39;45.0%22E/@40.0421532,116.2787023,18.25z/data=!4m5!3m4!1s0x0:0x0!8m2!3d40.0419444!4d116.2791667" target="_blank" rel="noopener">https://www.google.com/maps/place/40%C2%B002&#39;31.0%22N+116%C2%B016&#39;45.0%22E/@40.0421532,116.2787023,18.25z/data=!4m5!3m4!1s0x0:0x0!8m2!3d40.0419444!4d116.2791667</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1894ec73bfd21f4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>谷歌地球更直观点<a href="https://earth.google.com/web/@40.0419444,116.2791667,49.21370311a,786.12898499d,35y,0h,45t,0r/data=CjwaOhIyCgAZCyAhb14FREAhdqgB3t0RXUAqHDQwwrAwMiczMS4wIk4gMTE2wrAxNic0NS4wIkUYAiABKAIoAg" target="_blank" rel="noopener">https://earth.google.com/web/@40.0419444,116.2791667,49.21370311a,786.12898499d,35y,0h,45t,0r/data=CjwaOhIyCgAZCyAhb14FREAhdqgB3t0RXUAqHDQwwrAwMiczMS4wIk4gMTE2wrAxNic0NS4wIkUYAiABKAIoAg</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-9e7023fa1c7daf92.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="微信发原图"><a href="#微信发原图" class="headerlink" title="微信发原图"></a>微信发原图</h3><p>上面那个话题说微信发原图可泄露位置信息，我测试了下，微信发送图片的时候有默认是不带原图的，这样发出去的图片EXIF/GPS信息也会被抹去，如果要发原图需要选中按钮，这样发出去图片中的EXIF信息将会被保存。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-fe4518a06f0ac838.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br> 发原图的照片通过在电脑上可以看到exif信息，所以默认直接发送图片不用担心泄露你的位置信息。</p>
<p>但如果你用的某些APP或网站，不确认他们是否会直接发送并显示原图，最好关闭手机拍照的定位功能，删除图片的exif信息再分享出去。</p>
<h3 id="清除exif"><a href="#清除exif" class="headerlink" title="清除exif"></a>清除exif</h3><p>Windows上有个选项可以删除exif<br><img src="https://upload-images.jianshu.io/upload_images/17817191-fccf4538c2942cbb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>但不知道为什么我这删除失败了，大家可以试试自己的电脑。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-18ca137a25062227.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>所以我用了命令行工具exiftool  <a href="https://sno.phy.queensu.ca/~phil/exiftool/" target="_blank" rel="noopener">https://sno.phy.queensu.ca/~phil/exiftool/</a> </p>
<p>用exiftool 再看上面那张图片的详情，非常详细<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b772aff09e4182d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>一行命令清除图片所有exif信息。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ exiftool -all= sina.jpg</span><br><span class="line">    <span class="number">1</span> image files updated</span><br></pre></td></tr></table></figure></p>
<p>还可以修改图片的作者。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">exiftool -artist=susheng sina.jpg</span><br><span class="line">    <span class="number">1</span> image files updated</span><br></pre></td></tr></table></figure></p>
<p>其他常用命令<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"> exiftool -gps:all= sina.jpg  #删除gps信息</span><br><span class="line"> exiftool -all= sina.jpg  #删除所有信息</span><br><span class="line"> exiftool -all= --exif:all sina.jpg  #删除EXIF以外的所有信息</span><br><span class="line"> exiftool -artist=标签名称 sina.jpg            #写入艺术家标签</span><br><span class="line">exiftool -artist=标签名称 a.jpg b.jpg c.jpg   #写多个文件</span><br><span class="line"> exiftool -artist=标签名称  /exiftoolTest      #所有文件 exiftoolTest为文件夹</span><br></pre></td></tr></table></figure></p>
<p>清除exif后的图片再看拍摄日期和地理位置信息已经没了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b4c8b162461f9343.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-125fa4e6bc0e724a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果嫌命令行麻烦可以使用这个软件，公众号内回复 <code>exif</code> 获取。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a65076a837b339be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>除了小心手机照片的exif泄露你的隐私，网上晒图也有风险，之前在微博上看到一个妹子晒图被人找到具体位置， 我只截了几张图，有兴趣去微博看，微博地址<a href="https://weibo.com/1627825392/IdCbBpaWv" target="_blank" rel="noopener">https://weibo.com/1627825392/IdCbBpaWv</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-d21b354503206505.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-3cb2c66e9276bf6e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-d09afae7de4eef29.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/XTn8wPEyThacR3GLHyzBLA" target="_blank" rel="noopener">2019年11月最新使用油猴加速百度网盘下载方法</a></p>
<p><a href="https://mp.weixin.qq.com/s/K5-1y2RRcgAu9sRsxKfZpQ" target="_blank" rel="noopener">用 Markdown 写简历和 PPT</a></p>
<p><a href="https://mp.weixin.qq.com/s/ThUw9i43paFhXfPxF8mvyQ" target="_blank" rel="noopener">那些有趣的网站</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a><br> <img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>EXIF信息在线删除工具<a href="https://coding.tools/cn/exif-remover" target="_blank" rel="noopener">https://coding.tools/cn/exif-remover</a>  <a href="http://www.exiferaser.com/" target="_blank" rel="noopener">http://www.exiferaser.com/</a><br>有没有技术可以判断一张图片是否被PS过<a href="https://www.zhihu.com/question/19720234" target="_blank" rel="noopener">https://www.zhihu.com/question/19720234</a><br>隐藏在图片中的重要信息 <a href="https://feei.cn/exif/" target="_blank" rel="noopener">https://feei.cn/exif/</a><br>Python 来删除照片的 Exif 信息 <a href="https://www.dreamxu.com/protection-of-privacy-the-image-exif-information/" target="_blank" rel="noopener">https://www.dreamxu.com/protection-of-privacy-the-image-exif-information/</a><br>如何保护自己的隐私，工具删除图片的Exif 信息<a href="https://zhuanlan.zhihu.com/p/60332142" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/60332142</a><br>Convert PDF to Images with Pdftoppm <a href="https://jdhao.github.io/2019/11/14/convert_pdf_to_images_pdftoppm/" target="_blank" rel="noopener">https://jdhao.github.io/2019/11/14/convert_pdf_to_images_pdftoppm/</a><br><a href="http://www.nicetool.net/app/exif.html" target="_blank" rel="noopener">http://www.nicetool.net/app/exif.html</a><br><a href="http://www.atoolbox.net/Tool.php?Id=721" target="_blank" rel="noopener">http://www.atoolbox.net/Tool.php?Id=721</a><br><a href="https://www.dute.org/exif" target="_blank" rel="noopener">https://www.dute.org/exif</a><br>使用Python获取照片Exif信息 <a href="https://www.biaodianfu.com/exif-python.html" target="_blank" rel="noopener">https://www.biaodianfu.com/exif-python.html</a><br>一键获取图片 exif 信息，图片在线获取 exif 信息<a href="https://yijiangaitu.com/exif" target="_blank" rel="noopener">https://yijiangaitu.com/exif</a><br>照片EXIF元数据科普 <a href="https://www.sankengriji.com/article/58.html" target="_blank" rel="noopener">https://www.sankengriji.com/article/58.html</a><br>教你通过照片的EXIF信息来确定拍照的实际地理位置<a href="http://ons.me/460.html" target="_blank" rel="noopener">http://ons.me/460.html</a><br>PHP如何读取照片的Exif信息<a href="https://www.qttc.net/278_php_read_exif_from_photo.html" target="_blank" rel="noopener">https://www.qttc.net/278_php_read_exif_from_photo.html</a><br>浅谈互联网那些防不胜防的人肉搜索技巧 <a href="https://mp.weixin.qq.com/s/fHUQUSjBXWY151h0l9RsXw" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/fHUQUSjBXWY151h0l9RsXw</a><br>ip定位 <a href="http://www.ipplus360.com" target="_blank" rel="noopener">www.ipplus360.com</a><br>经纬度查询map.yanue.net<br>通过法院执行信息，我猜出了王思聪身份证号码 <a href="https://mp.weixin.qq.com/s/ePY52C4HnJJ0-efUxXxRrA" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/ePY52C4HnJJ0-efUxXxRrA</a><br> 注册了哪些网站<a href="https://www.reg007.com/" target="_blank" rel="noopener">https://www.reg007.com/</a><br>如何防止自己被人肉搜索到 <a href="https://www.zhihu.com/question/48691691#answer-40338211" target="_blank" rel="noopener">https://www.zhihu.com/question/48691691#answer-40338211</a> <a href="https://cn.v2ex.com/t/624217#reply83" target="_blank" rel="noopener">https://cn.v2ex.com/t/624217#reply83</a><br> 我人肉了一个用果照威胁女孩的变态 <a href="https://paper.seebug.org/810/" target="_blank" rel="noopener">https://paper.seebug.org/810/</a>  <a href="https://cn.v2ex.com/t/535557" target="_blank" rel="noopener">https://cn.v2ex.com/t/535557</a><br>成功地报复了一个骗子，网络诈骗的。这一定是我做过的最骚的操作。 <a href="https://www.zhihu.com/question/293315890/answer/523802607" target="_blank" rel="noopener">https://www.zhihu.com/question/293315890/answer/523802607</a><br>别惹程序员系列之《老婆沉迷赌博输了一套房，我顺藤摸瓜端了澳门赌场》<br>有课代表做了总结：<br>1、站长之家查 whois<br>2、站长之家的Ping功能查询了一下有没有加CDN<br>3、同IP网站查询的功能进行搜索<br>4、通过QQ空间发现其他QQ信息<br>5、利用QQ的忘记密码功能，查询了一下这两个QQ绑定的手机号<br>6、利用贴吧的高级搜索功能查询到网名为y的QQ<br>7、社工库里面尝试了一下能不能查询到这个QQ的老密<br>8、查到的密码用MD5进行加密了，我们到MD5的解密网站去进行解密<br>9、查询到的密码试着登录（很多人都喜欢把自己的ID/姓名/手机号放到自己的密码里面）<br>10、谷歌搜索他的ID，找到有用的信息，例如生活 QQ、身份证号码<br>11、QQ邮箱尝试能不能搜索出支付宝<br>12、利用支付宝转账功能的姓名验证获取到了他的全名<br>13、身份证号+姓名就可以查询出身份证上的照片<br>14、用Telegram的社工库查询接口对他的生活进行查询<br>15、通过他的生活QQ进行域名Whois反查<br>16、通过MagicEXIF定位到了他的家庭地址<br>收集完他的基本信息后，开始谈判、最后报警 <a href="https://mp.weixin.qq.com/s/gL0pCFnJsOhrkNsVUi6GWQ" target="_blank" rel="noopener">https://mp.weixin.qq.com/s/gL0pCFnJsOhrkNsVUi6GWQ</a><br>查看exif  <a href="https://www.sojson.com/image/exif.html" target="_blank" rel="noopener">https://www.sojson.com/image/exif.html</a><br>EXIF查询 <a href="https://exif.tuchong.com/" target="_blank" rel="noopener">https://exif.tuchong.com/</a><br>图片exif查看器 <a href="https://www.toolnb.com/tools/getexif.html" target="_blank" rel="noopener">https://www.toolnb.com/tools/getexif.html</a><br>在线查看数码照片Exif信息 <a href="https://www.gaitubao.com/exif" target="_blank" rel="noopener">https://www.gaitubao.com/exif</a><br>2年前微信派就发过文章<a href="https://mp.weixin.qq.com/s/bFbU2Q8yWcI3rr-HYptY3A" target="_blank" rel="noopener">关于发送原图，这些事你得知道</a><br>自己用的修改图片EXIF信息软件<a href="https://www.52pojie.cn/thread-203604-1-1.html" target="_blank" rel="noopener">https://www.52pojie.cn/thread-203604-1-1.html</a><br>exiftool(-k -r -charset filename= -all= -overwrite_original).exe<br>ExifTagRemove <a href="https://www.lanzous.com/i3ja7ba" target="_blank" rel="noopener">https://www.lanzous.com/i3ja7ba</a>   <a href="https://www.lanzous.com/i3ja83i" target="_blank" rel="noopener">https://www.lanzous.com/i3ja83i</a><br>删除EXIF信息的软件 <a href="https://www.52pojie.cn/thread-919176-1-1.html" target="_blank" rel="noopener">https://www.52pojie.cn/thread-919176-1-1.html</a><br><a href="https://mlog.club/user/616" target="_blank" rel="noopener">https://mlog.club/user/616</a><br><a href="https://wemp.app/posts/e6ebf85a-25eb-41e4-81f2-49f84b1f22e3" target="_blank" rel="noopener">https://wemp.app/posts/e6ebf85a-25eb-41e4-81f2-49f84b1f22e3</a><br><a href="http://www.python88.com/topic/50750" target="_blank" rel="noopener">http://www.python88.com/topic/50750</a><br><a href="http://www.exiferaser.com/ver/1.1" target="_blank" rel="noopener">http://www.exiferaser.com/ver/1.1</a><br>ip查询 <a href="https://github.com.ipaddress.com/" target="_blank" rel="noopener">https://github.com.ipaddress.com/</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/12/05/那些有趣的网站/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/12/05/那些有趣的网站/" itemprop="url">那些有趣的网站</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-05T20:47:20+08:00">
                2019-12-05
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  739 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  2 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>之前分享过<a href="https://mp.weixin.qq.com/s/11w7ulUxtRoSuZztMGR_qw" target="_blank" rel="noopener">那些有意思的网站</a> ，这里继续分享一波，也许你用得上。</p>
<h3 id="福利单词"><a href="#福利单词" class="headerlink" title="福利单词"></a>福利单词</h3><p>一边背单词一边看妹子的网站，用电脑打开，配合ctrl+w 关闭新窗口，不知不觉就背了百来个词了 <a href="https://easychen.gitee.io/foxdict/" target="_blank" rel="noopener">https://easychen.gitee.io/foxdict/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-dbcaff8a58971bd9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="工资计算器"><a href="#工资计算器" class="headerlink" title="工资计算器"></a>工资计算器</h3><p>简单、精准、免费的 五险一金及税后工资计算器 周边计算服务 <a href="https://hizdm.cn/bonus/" target="_blank" rel="noopener">https://hizdm.cn/bonus/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1c92d79c1772e06a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>北京为例，月薪5万，税后只有36832.24 元。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-41214aba3f11915f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>你可以选择自己的城市<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5ed56e1fd0ad2486.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="Logo-生成器"><a href="#Logo-生成器" class="headerlink" title="Logo 生成器"></a>Logo 生成器</h3><p>这是一个简单的 Logo 生成器，可以让你快速制作 Pornhub、YouTube 风格的 Logo <a href="https://www.zerobbs.net/pornhub/" target="_blank" rel="noopener">https://www.zerobbs.net/pornhub/</a>  <a href="https://www.zerobbs.net/youtube/" target="_blank" rel="noopener">https://www.zerobbs.net/youtube/</a> <a href="https://github.com/kasuganosoras/logo-maker" target="_blank" rel="noopener">https://github.com/kasuganosoras/logo-maker</a> <a href="https://github.com/bestony/logoly" target="_blank" rel="noopener">https://github.com/bestony/logoly</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-b4f5731e29b76ccf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>比如生成一个 苏生不惑 ，用这个做公众号头像怎么样？<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3f2b25b672a13036.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="你好污啊"><a href="#你好污啊" class="headerlink" title="你好污啊"></a>你好污啊</h3><p>全网最污的人都在这里了 <a href="https://nihaowua.90so.net/" target="_blank" rel="noopener">https://nihaowua.90so.net/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-f2835a07ce3da010.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-3a54234755b950d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="在线扫雷"><a href="#在线扫雷" class="headerlink" title="在线扫雷"></a>在线扫雷</h3><p>扫雷经典游戏，应该很多人在Windows下玩过，现在可以在线玩了<a href="https://www.saolei.org.cn/" target="_blank" rel="noopener">https://www.saolei.org.cn/</a> ，有兴趣还可以玩玩五子棋，坦克。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ba262cce21a5e748.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="微博热搜历史"><a href="#微博热搜历史" class="headerlink" title="微博热搜历史"></a>微博热搜历史</h3><p>这里可以查看微博的热搜历史，生成热点词云图。<a href="https://www.enlightent.cn/research/rank/weiboSearchRank" target="_blank" rel="noopener">https://www.enlightent.cn/research/rank/weiboSearchRank</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-621240cc7eae82df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>选择历史11月1号的微博热搜<br><img src="https://upload-images.jianshu.io/upload_images/17817191-827f5052ffcf50ad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>话题第一是杨超越致歉。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ec54c07f6a9c10c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="中国历史时间轴"><a href="#中国历史时间轴" class="headerlink" title="中国历史时间轴"></a>中国历史时间轴</h3><p><a href="http://www.lishiju.net/timeline.html" target="_blank" rel="noopener">http://www.lishiju.net/timeline.html</a>  从公元前2070年到今天，让你清晰的了解中国上下5千年历史。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-134edf2e759c2d3c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-9c65775408431dd5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="虚假截图助手"><a href="#虚假截图助手" class="headerlink" title="虚假截图助手"></a>虚假截图助手</h3><p>这是一个可以“伪造”微博、知乎、豆瓣、简书等网站界面截图的网站，看看鲁迅的微博又说什么了。<a href="https://fakes.netlify.com/#/sina/simple" target="_blank" rel="noopener">https://fakes.netlify.com/#/sina/simple</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1e8ab2216b20232a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>之前还有人伪造王思聪的微博发支付宝红包，其他那个数字是自己的，也不知道薅了多少支付宝羊毛，厉害。<br>总之，不要轻信截图。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f0fba24614716ee0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="关键词找-电影"><a href="#关键词找-电影" class="headerlink" title="关键词找 电影"></a>关键词找 电影</h3><p><a href="https://www.whatismymovie.com/" target="_blank" rel="noopener">https://www.whatismymovie.com/</a>  搜索<code>freedom</code>可以找到在电影《勇敢的心》1小时54分出现。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-40c2fc29fc579a88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-d06db205210a39b7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="知识提取搜索引擎"><a href="#知识提取搜索引擎" class="headerlink" title="知识提取搜索引擎"></a>知识提取搜索引擎</h3><p><a href="http://magi.com/" target="_blank" rel="noopener">http://magi.com/</a> 这个不同于百度谷歌， 搜索 pgone 有亮点。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-917640abeeb79463.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="马云模拟器"><a href="#马云模拟器" class="headerlink" title="马云模拟器"></a>马云模拟器</h3><p><a href="https://lemonjing.com/" target="_blank" rel="noopener">https://lemonjing.com/</a> 在马云模拟器，你可以体验花光马云的2700多亿是什么感觉，买起来吧 。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-72d12a0b25ece51a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1e93d9c368e24aa0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="举牌小人"><a href="#举牌小人" class="headerlink" title="举牌小人"></a>举牌小人</h3><p>举牌小人来自一个台湾插画家设计，<a href="http://upuptoyou.com/" target="_blank" rel="noopener">http://upuptoyou.com/</a> 提供生成这种图片服务。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b1554a9c3008e286.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果比较慢，可以使用国内的 <a href="http://1.hus.tcapps.twocola.com/" target="_blank" rel="noopener">http://1.hus.tcapps.twocola.com/</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-50c6bb956d230458.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/952eqef1Rm3HpH5DYbTjZg" target="_blank" rel="noopener">那些我关注的 b 站 up 主</a></p>
<p><a href="https://mp.weixin.qq.com/s/Y8wlutMFZymzCAKM3fp8SA" target="_blank" rel="noopener">那些我常听的中文播客节目</a></p>
<p><a href="https://mp.weixin.qq.com/s/XTn8wPEyThacR3GLHyzBLA" target="_blank" rel="noopener">2019年11月最新使用油猴加速百度网盘下载方法</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a><br> <img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/12/03/用-Markdown-来写简历和-PPT/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/12/03/用-Markdown-来写简历和-PPT/" itemprop="url">用 Markdown 来写简历和 PPT</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-03T20:09:00+08:00">
                2019-12-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.3k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>之前写过 markdown 的使用<a href="https://mp.weixin.qq.com/s/TuJIqv5wv27avFKG8zmJUQ" target="_blank" rel="noopener">我是如何用 Markdown 写公众号文章的</a> ，强烈建议你花10分钟学学markdown，那时候你才知道原来写作可以如此顺畅。</p>
<p>除了网页版 markdown 编辑器， 这里推荐一款非常好用的支持实时预览的markdown客户端软件 Typora ，它支持 Windows mac Linux等系统，能自动保存，不用担心写好的文档丢失，导入文件格式支持.docx, .latex,.epub等，导出文件格式支持 PDF，HTML等格式，如果要导出LaTeX格式需要安装 Pandoc 插件。</p>
<p>软件下载地址 <a href="https://github.com/typora" target="_blank" rel="noopener">https://github.com/typora</a> <a href="https://www.typora.io/" target="_blank" rel="noopener">https://www.typora.io/</a> 。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-eb5719fb2c6a7255.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>使用markdown语法编辑（非常易学）。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e407c54f52452211.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>退出源代码模式可以显示效果（可以看到字体加粗了），最后保存文件名后缀为.md，然后可以直接用Typora打开。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-7e5c6b81a8a54beb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>比如我之前用一个工具将 MySQL 表结构生成 Markdown 文件<a href="https://learnku.com/articles/36523" target="_blank" rel="noopener">https://learnku.com/articles/36523</a> </p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-6c01906a534a5226.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>然后将markdown文件导出为PDF<br><img src="https://upload-images.jianshu.io/upload_images/17817191-6cbf883442ccbad0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-a3342d4fd2acc58c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>效果如图，左侧还有目录结构，是每个表的表名。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-06ed8ba88dc2f6d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>markdown文件还可以导出为HTML，这样可以直接复制到微信公众号发布，当然这有点麻烦，还是建议使用 <a href="https://mdnice.com/" target="_blank" rel="noopener">https://mdnice.com/</a> 这样的在线工具。</p>
<p>导入文件需要 pandoc插件支持  <a href="https://pandoc.org/installing.html" target="_blank" rel="noopener">https://pandoc.org/installing.html</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-2009e8b3e1d5014a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-711213f2c8723889.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="markdown简历"><a href="#markdown简历" class="headerlink" title="markdown简历"></a>markdown简历</h3><p>学会了markdown，就可以用来写简历了，比如之前写过的<a href="https://mp.weixin.qq.com/s/sng3uK9Nge1OD2gc5DDuZg" target="_blank" rel="noopener">那些你可能用得上的简历写作工具</a> ，这里推荐一个非常好用的在线markdown工具 <a href="http://resumd.t9t.io/" target="_blank" rel="noopener">http://resumd.t9t.io/</a>  ，可以自定义样式(GitHub theme, timqian.com theme, TUI theme)，最后导出为md PDF 或者HTML。</p>
<p> 比如我之前的文章 <a href="https://mp.weixin.qq.com/s/iL6WyI-TChtjZMuu5G5W8A" target="_blank" rel="noopener">公众号苏生不惑原创文章整理</a>  copy到这里。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e3cefb291eaabcfc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>导出为resume.md，然后用 Typora 打开。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-34274530f81b0382.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>导出为HTML格式，用浏览器打开。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f17f14b8d4426801.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>导出为PDF ，用浏览器打开。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c569963b22ae707c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-9119477400a44191.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>最后将写好的简历分享出来发给别人看。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c5a356483a1b12df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果遇到问题可以到 <a href="https://github.com/timqian/resumd/issues" target="_blank" rel="noopener">https://github.com/timqian/resumd/issues</a> 提问。</p>
<h3 id="Markdown-文档转成高大上-PPT"><a href="#Markdown-文档转成高大上-PPT" class="headerlink" title="Markdown 文档转成高大上 PPT"></a>Markdown 文档转成高大上 PPT</h3><p>累死累活干不过做 PPT 的，那就将markdown转为PPT吧，推荐一款能将 Markdown 文档转成高大上 PPT 的开源工具，支持图表、流程图、数学符号、自定义主题配色以及样式等  <a href="https://github.com/ksky521/nodeppt" target="_blank" rel="noopener">https://github.com/ksky521/nodeppt</a> <a href="https://nodeppt.js.org/#slide=1" target="_blank" rel="noopener">https://nodeppt.js.org/#slide=1</a> 直接按方向键翻页，和使用office一样。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-92bc1052487eb294.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>使用方法很简单<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">npm install -g nodeppt</span><br><span class="line"> </span><br><span class="line"> # create a new slide with an official template</span><br><span class="line">$ nodeppt <span class="keyword">new</span> slide.md</span><br><span class="line"></span><br><span class="line"># create a new slide straight from a github template</span><br><span class="line">$ nodeppt <span class="keyword">new</span> slide.md -t username/repo</span><br><span class="line"></span><br><span class="line"># start local sever show slide</span><br><span class="line">$ nodeppt serve slide.md</span><br><span class="line"></span><br><span class="line"># to build a slide</span><br><span class="line">$ nodeppt build slide.md</span><br></pre></td></tr></table></figure></p>
<p>类似的还有  <a href="https://eloc.now.sh/" target="_blank" rel="noopener">https://eloc.now.sh/</a>  <a href="https://badgen-5min.now.sh/" target="_blank" rel="noopener">https://badgen-5min.now.sh/</a><br><a href="https://github.com/amio/eloc" target="_blank" rel="noopener">https://github.com/amio/eloc</a> <a href="https://github.com/hakimel/reveal.js" target="_blank" rel="noopener">https://github.com/hakimel/reveal.js</a> ，我之前也写过 <a href="https://mp.weixin.qq.com/s/WNuRKxtvwK_6AAnKmNU8yw" target="_blank" rel="noopener">ppt 神器 reveal</a> ，我还做个了周杰伦的在线个人PPT <a href="https://sushengbuhuo.gitee.io/blog/jay/#/start" target="_blank" rel="noopener">https://sushengbuhuo.gitee.io/blog/jay/#/start</a> 。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-96ccf00df3fd5ce4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>最后推荐一个  Markdown 的表格格式在线生成工具，图形化操作，一键生成，可以生成 Letex、HTML Table、MediaWiki 等，有点意思，可以玩玩 <a href="https://www.tablesgenerator.com/" target="_blank" rel="noopener">https://www.tablesgenerator.com/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-047d1c257756b3e0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>在线简历 <a href="https://resume.mdnice.com/" target="_blank" rel="noopener">https://resume.mdnice.com/</a><br>Typora 完全使用详解 <a href="https://sspai.com/post/54912" target="_blank" rel="noopener">https://sspai.com/post/54912</a><br>推介一个不错的在线公式、图形编辑生成器，可以在线转化为 SVG、Letex 格式，方便的插入支持 Letex 的 Markdown 编辑器中，在支持的编辑器前后加上 <code>$$</code> 即可，附上我在 Typora 中画的一个公式～  <a href="https://www.mathcha.io" target="_blank" rel="noopener">https://www.mathcha.io</a><br>推介一个炫酷的字符码图在线生成工具，附上我自己画的一个 Nodejs 事件循环机制图～ <a href="http://asciiflow.com/" target="_blank" rel="noopener">http://asciiflow.com/</a><br>让 Markdown 写作更简单，免费极简编辑器 <a href="https://sspai.com/post/30292" target="_blank" rel="noopener">https://sspai.com/post/30292</a><br>使用 Pandoc 与 Markdown 生成 PDF 文件 <a href="https://jdhao.github.io/2017/12/10/pandoc-markdown-with-chinese/" target="_blank" rel="noopener">https://jdhao.github.io/2017/12/10/pandoc-markdown-with-chinese/</a><br><a href="https://github.com/jgm/pandoc/wiki/Pandoc-With-Chinese-(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)" target="_blank" rel="noopener">https://github.com/jgm/pandoc/wiki/Pandoc-With-Chinese-(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)</a><br><a href="https://www.bbsmax.com/A/A7zgplD1J4/" target="_blank" rel="noopener">https://www.bbsmax.com/A/A7zgplD1J4/</a><br><a href="https://www.bajins.com/Other/Markdown%E5%B7%A5%E5%85%B7.html#微信公众号排版" target="_blank" rel="noopener">https://www.bajins.com/Other/Markdown%E5%B7%A5%E5%85%B7.html#微信公众号排版</a> <a href="http://cv.ftqq.com/#" target="_blank" rel="noopener">http://cv.ftqq.com/#</a><br>简历<a href="https://github.com/geekcompany/DeerResume" target="_blank" rel="noopener">https://github.com/geekcompany/DeerResume</a><br>使用 Markdown 制作漂亮的在线简历 <a href="https://bigliao.github.io/markCV/" target="_blank" rel="noopener">https://bigliao.github.io/markCV/</a>  <a href="https://github.com/BigLiao/markCV" target="_blank" rel="noopener">https://github.com/BigLiao/markCV</a><br>简历<a href="https://github.com/timqian/resumd" target="_blank" rel="noopener">https://github.com/timqian/resumd</a><br>一款 Markdown 语法排版简历的工具 <a href="https://github.com/mdnice/markdown-resume" target="_blank" rel="noopener">https://github.com/mdnice/markdown-resume</a><br><a href="https://openwrite.cn" target="_blank" rel="noopener">https://openwrite.cn</a><br><a href="https://www.mdnice.com/" target="_blank" rel="noopener">https://www.mdnice.com/</a><br><a href="http://blog.didispace.com/tools/online-markdown/" target="_blank" rel="noopener">http://blog.didispace.com/tools/online-markdown/</a><br><a href="https://md.phodal.com/" target="_blank" rel="noopener">https://md.phodal.com/</a><br><a href="http://md.codingpy.com/" target="_blank" rel="noopener">http://md.codingpy.com/</a><br><a href="http://js8.in/mpeditor/" target="_blank" rel="noopener">http://js8.in/mpeditor/</a><br>公众号排版 <a href="https://github.com/didadi599/wechat-markdown-editor" target="_blank" rel="noopener">https://github.com/didadi599/wechat-markdown-editor</a><br>通过导入json、csv、excel、html table生成Markdown表格，一个写博客必备神器 <a href="https://tableconvert.com/" target="_blank" rel="noopener">https://tableconvert.com/</a><br>一款基于 Vue、Vditor，为未来而构建的在线 Markdown 编辑器；轻量且强大：内置粘贴 HTML 自动转换为 Markdown，支持流程图、甘特图、时序图、任务列表，可导出携带样式的图片、PDF、微信公众号特制的 HTML 等等。 <a href="https://markdown.lovejade.cn/export/pdf/" target="_blank" rel="noopener">https://markdown.lovejade.cn/export/pdf/</a>   <a href="https://www.lovejade.cn/zh/works/" target="_blank" rel="noopener">https://www.lovejade.cn/zh/works/</a> </p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/952eqef1Rm3HpH5DYbTjZg" target="_blank" rel="noopener">那些我关注的 b 站 up 主</a></p>
<p><a href="https://mp.weixin.qq.com/s/Y8wlutMFZymzCAKM3fp8SA" target="_blank" rel="noopener">那些我常听的中文播客节目</a></p>
<p><a href="https://mp.weixin.qq.com/s/XTn8wPEyThacR3GLHyzBLA" target="_blank" rel="noopener">2019年11月最新使用油猴加速百度网盘下载方法</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a></p>
<p> <img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/29/2019年11月最新使用油猴加速百度网盘下载方法/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/29/2019年11月最新使用油猴加速百度网盘下载方法/" itemprop="url">2019年11月最新使用油猴加速百度网盘下载方法</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-29T20:22:39+08:00">
                2019-11-29
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  5 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>百度网盘是目前最好的文件存储和分享工具了，之前已经写过<br><a href="https://mp.weixin.qq.com/s/H8VPSGt62-tblpgWkleQoQ" target="_blank" rel="noopener">那些你可能不知道的百度文库/网盘快速下载工具</a><br><a href="https://mp.weixin.qq.com/s/MUIPj4OgSxAeRl5Hk-2tuw" target="_blank" rel="noopener">没有提取码怎么获取百度网盘资源？</a><br>常用的网盘下载方法如 pandownload 已经失效了，这里分享一种最新可加速下载的方法（速度可达6MB/s），就是油猴+IDM了，很简单，下面看看怎么用吧。</p>
<h3 id="idm"><a href="#idm" class="headerlink" title="idm"></a>idm</h3><p>Internet Download Manager是一个用于Windows系统的多线程下载神器，能将下载速度提高最多5倍，支持所有主流浏览器，几乎能下载网页中的所有数据，包括视频、音频，图片等。</p>
<p> 先下载idm软件（在公众号回复 <code>idm</code> 获取软件）后会直接安装好Chrome扩展。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-18ca349b6e13c784.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>在谷歌浏览器扩展程序 chrome://extensions/ 里开启idm扩展。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-9162fd4c15f7d2c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>页面上右键就可以看到idm下载按钮了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ae19d78b4835b2d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>点击下载会启动IDM软件下载文件。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-bb164bc04977ebae.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>比如下载我之前的文章 <a href="https://mp.weixin.qq.com/s/Y8wlutMFZymzCAKM3fp8SA" target="_blank" rel="noopener">那些我常听的中文播客节目</a> 中的音频。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-19e6df5b1e625802.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-da399aa8f4dd4ab5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="油猴扩展"><a href="#油猴扩展" class="headerlink" title="油猴扩展"></a>油猴扩展</h3><p>油猴脚本 Tampermonkey 是一款免费的浏览器扩展和流行的用户脚本管理器，它适用于 Chrome, Microsoft Edge, Safari, Firefox等主流浏览器。<br>如果你还没用过油猴，可以看看之前的文章<a href="https://mp.weixin.qq.com/s/adJFh_9LH0N-vvvYaiQqXg" target="_blank" rel="noopener">Chrome 浏览器扩展神器油猴</a> ，油猴Chrome扩展地址   <a href="https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=zh-CN" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=zh-CN</a> </p>
<p>下载Chrome 扩展需要先上谷歌，公众号内回复 <code>谷歌</code> 获取方法，也可以回复 <code>油猴</code> 获取扩展crx文件，然后将扩展文件拖进扩展程序，如果遇到问题比如提示 <code>该扩展程序未列在 Chrome 网上应用店中，并可能是在您不知情的情况下添加的</code>或者<code>程序包无效</code>。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c41e8caad9a5e2d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>先把文件后缀.crx 改成 .rar，然后解压得到一个文件夹，再打开chrome://extensions/ 谷歌扩展管理，点击右上角的开发者模式，就可以看到<code>加载已解压的扩展程序</code>，选择刚才解压好的文件夹，确认新增扩展程序就安装好了油猴扩展（安装其他扩展类似）。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-76a8c135457134b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>安装完后右上角就有油猴按钮了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ec752262f74798c6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="网盘助手脚本"><a href="#网盘助手脚本" class="headerlink" title="网盘助手脚本"></a>网盘助手脚本</h3><p>有了油猴还需要安装对应的脚本，这个大概是目前最优雅好用的网盘助手脚本了，脚本主要功能有：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="number">1</span>]百度网盘、腾讯微云、蓝奏云万能钥匙</span><br><span class="line">[<span class="number">2</span>]百度网盘生成并展示下载链接 </span><br><span class="line">[<span class="number">3</span>]百度网盘分享时自定义提取码</span><br></pre></td></tr></table></figure></p>
<p>脚本地址<a href="https://greasyfork.org/zh-CN/scripts/378301-%E7%BD%91%E7%9B%98%E5%8A%A9%E6%89%8B" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/378301-%E7%BD%91%E7%9B%98%E5%8A%A9%E6%89%8B</a><br>点击这里安装，我已经安装过了所以显示重新安装。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-253683af71ddc26e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>安装后打开这个网盘链接 <a href="https://pan.baidu.com/s/1EgMaezKmv6ofH77F2DvsDw" target="_blank" rel="noopener">https://pan.baidu.com/s/1EgMaezKmv6ofH77F2DvsDw</a> 不用自己输入提取码了，它会自动帮你填写。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-375da0c0ab5007f7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>分享文件时还可以自定义提取码，比如 8866，我这里生成了一个分享链接<a href="https://pan.baidu.com/s/1MDv3mdhjRF65_sp20dhAnQ" target="_blank" rel="noopener">https://pan.baidu.com/s/1MDv3mdhjRF65_sp20dhAnQ</a> 提取码: 8866<br><img src="https://upload-images.jianshu.io/upload_images/17817191-aea6536102d22142.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="下载网盘文件"><a href="#下载网盘文件" class="headerlink" title="下载网盘文件"></a>下载网盘文件</h3><p>有了idm和油猴就可以开始下载文件了，这里下载周星驰的电影《唐伯虎点秋香》（想获取周星驰所有电影回复<code>周星驰</code>）<br>打开你的网盘主页 <a href="https://pan.baidu.com/disk/home" target="_blank" rel="noopener">https://pan.baidu.com/disk/home</a> ，如果是别人分享的文件，先保存到自己网盘，然后选中文件，点击生成链接会生成一个mkv地址 <a href="https://pcs.baidu.com/rest/2.0/pcs/file?method=download&amp;app_id=250528&amp;path=%2F%E7%94%B5%E5%BD%B1%2F%E5%91%A8%E6%98%9F%E9%A9%B0%E7%94%B5%E5%BD%B1%2F%E5%94%90%E4%BC%AF%E8%99%8E%E7%82%B9%E7%A7%8B%E9%A6%99.mkv&amp;filename=%E5%94%90%E4%BC%AF%E8%99%8E%E7%82%B9%E7%A7%8B%E9%A6%99.mkv" target="_blank" rel="noopener">https://pcs.baidu.com/rest/2.0/pcs/file?method=download&amp;app_id=250528&amp;path=%2F%E7%94%B5%E5%BD%B1%2F%E5%91%A8%E6%98%9F%E9%A9%B0%E7%94%B5%E5%BD%B1%2F%E5%94%90%E4%BC%AF%E8%99%8E%E7%82%B9%E7%A7%8B%E9%A6%99.mkv&amp;filename=%E5%94%90%E4%BC%AF%E8%99%8E%E7%82%B9%E7%A7%8B%E9%A6%99.mkv</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-23b88f68c2023d60.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>然后右键使用idm下载。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-deed723cc3d90cd0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>弹出IDM软件下载框<br><img src="https://upload-images.jianshu.io/upload_images/17817191-7699f2a19754a231.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>看看下载速度，最高可达6.3MB/s<br><img src="https://upload-images.jianshu.io/upload_images/17817191-bb37b1fa4d53dca4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-7ce8c538edd4292e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-8dac1abdcb89c5d5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>400MB的文件不到2分钟下载完。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a99ea71560473f11.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果出现 <code>HTTP/1.1 403</code> 无权限下载错误，在弹出的窗口里修改应用 ID 为 778750， 具体见<a href="http://pan.newday.me/script/option.html。如果" target="_blank" rel="noopener">http://pan.newday.me/script/option.html。如果</a> 778750 也不行，换 265486、309847 或 266719。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-a6958d9cb1a64937.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>再对比下使用百度网盘客户端下载速度99kB/s ，速度快了几十倍。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-29c41c235248c8db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>好了，油猴赶快用起来吧，如果有问题在文末可以留言。</p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>3个方法解决百度网盘限速 <a href="https://www.runningcheese.com/baiduyun" target="_blank" rel="noopener">https://www.runningcheese.com/baiduyun</a><br> <a href="https://www.baiduyun.wiki/zh-cn/assistant.html" target="_blank" rel="noopener">https://www.baiduyun.wiki/zh-cn/assistant.html</a><br><a href="http://pan.newday.me/" target="_blank" rel="noopener">http://pan.newday.me/</a><br>下载工具：<a href="https://www.lanzous.com/b0ug2rrc" target="_blank" rel="noopener">https://www.lanzous.com/b0ug2rrc</a><br>下载 xdown <a href="https://xdown.org/" target="_blank" rel="noopener">https://xdown.org/</a>  百度网盘下载助手<a href="https://greasyfork.org/zh-CN/scripts/390707" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/390707</a><br>Aria2下载助手<br>纯净无广告 配合aria2使用 百度网盘满速下载 哔哩哔哩下载和解除港澳台区域限制<br><a href="https://greasyfork.org/zh-CN/scripts/390707-aria2%E4%B8%8B%E8%BD%BD%E5%8A%A9%E6%89%8B" target="_blank" rel="noopener">https://greasyfork.org/zh-CN/scripts/390707-aria2%E4%B8%8B%E8%BD%BD%E5%8A%A9%E6%89%8B</a><br>【下载速度】理论速度100/8=12.5M/s,限速后下载速度在5kb~50kb浮动<br>如果出现 HTTP/1.1 403 错误，尝试将应用 ID 修改为： 778750。<br>如何修改应用 ID 呢？打开 <a href="http://pan.newday.me/script/option.html，在弹出的窗口里修改。" target="_blank" rel="noopener">http://pan.newday.me/script/option.html，在弹出的窗口里修改。</a><br>如果 778750 也不行的话，尝试 265486、309847 或者 266719。<br>亿寻 百度网盘不限速下载   <a href="https://www.52pojie.cn/thread-1055417-1-1.html" target="_blank" rel="noopener">https://www.52pojie.cn/thread-1055417-1-1.html</a><br>最新发现的百度网盘下载<a href="https://www.52pojie.cn/thread-1050407-1-1.html" target="_blank" rel="noopener">https://www.52pojie.cn/thread-1050407-1-1.html</a><br>网盘助手chrome 扩展地址<a href="https://chrome.google.com/webstore/detail/%E7%BD%91%E7%9B%98%E5%8A%A9%E6%89%8B/cfaglmggimoleoclaghmmboppofffdda" target="_blank" rel="noopener">https://chrome.google.com/webstore/detail/%E7%BD%91%E7%9B%98%E5%8A%A9%E6%89%8B/cfaglmggimoleoclaghmmboppofffdda</a><br>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/952eqef1Rm3HpH5DYbTjZg" target="_blank" rel="noopener">那些我关注的 b 站 up 主</a></p>
<p><a href="https://mp.weixin.qq.com/s/Y8wlutMFZymzCAKM3fp8SA" target="_blank" rel="noopener">那些我常听的中文播客节目</a></p>
<p><a href="https://mp.weixin.qq.com/s/FzccdcMol_DYQhUMPgbdyg" target="_blank" rel="noopener">双十一防虚假促销套路，先查询下商品历史价格</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a><br> <img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/27/无套路，公众号-苏生不惑-抽奖送现金红包/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/27/无套路，公众号-苏生不惑-抽奖送现金红包/" itemprop="url">无套路，公众号 苏生不惑 抽奖送现金红包</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-27T20:22:07+08:00">
                2019-11-27
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  531 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>抽奖在文末</p>
</blockquote>
<p>最近公众号来了不少新关注，有些人可能对我不了解，我目前在北京新浪工作，关于新浪可以看看我之前的文章 <a href="https://mp.weixin.qq.com/s/mI5kubVY2t5jwJ9ub7A1iA" target="_blank" rel="noopener">我的新浪工作日常</a></p>
<p>公众号陆陆续续更新了近70篇原创文章，连续坚持了半年每周更新2-3篇，也是不容易，之前10月份还整理过一次 <a href="https://mp.weixin.qq.com/s/iL6WyI-TChtjZMuu5G5W8A" target="_blank" rel="noopener">公众号苏生不惑原创文章整理</a> </p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-0d913855fcbdd912.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>这里再整理下10月后的原创文章。</p>
<p><a href="https://mp.weixin.qq.com/s/9XEABuraTAipZ_uZPDbQdQ" target="_blank" rel="noopener">那些我常用的 Chrome 扩展</a></p>
<p><a href="https://mp.weixin.qq.com/s/PGAdM0sS9dHstkbP0tOq8g" target="_blank" rel="noopener">那些我常用的 Chrome 扩展（二）</a></p>
<p><a href="https://mp.weixin.qq.com/s/7v9LHJX05Ybv39BzrMD0Uw" target="_blank" rel="noopener">那些你可能不知道的百度产品</a></p>
<p><a href="https://mp.weixin.qq.com/s/3npDt-hSe97L987Z_DaWCQ" target="_blank" rel="noopener">那些你可能不知道的腾讯产品</a></p>
<p><a href="https://mp.weixin.qq.com/s/NYrs5cluZgjvm85MXmiaKA" target="_blank" rel="noopener">那些在国内还能使用的谷歌产品</a></p>
<p><a href="https://mp.weixin.qq.com/s/H3RrK2oW1WoU2UASvfKLOw" target="_blank" rel="noopener">那些你可能需要的图片处理工具</a></p>
<p><a href="https://mp.weixin.qq.com/s/RWxn4_Qg_Z3bL4wKusndKA" target="_blank" rel="noopener">不会写Python代码如何抓取豆瓣电影 Top 250</a></p>
<p><a href="https://mp.weixin.qq.com/s/whcZis69KnIzEUVMtrjdmA" target="_blank" rel="noopener">Python 词云分析周杰伦新歌《说好不哭》</a></p>
<p><a href="https://mp.weixin.qq.com/s/7G3-yuJYz2tYAl3RU6FjfA" target="_blank" rel="noopener">2019 双十一京东全民养红包攻略分享</a></p>
<p><a href="https://mp.weixin.qq.com/s/LKDGKWi62J5Zyzh3rB-IiQ" target="_blank" rel="noopener">跟随时光机回到过去看看 2005 年的百度/腾讯/淘宝/谷歌</a></p>
<p><a href="https://mp.weixin.qq.com/s/A_Y0B86S30QD6d2dG1sWYQ" target="_blank" rel="noopener">如何快速找到电子书《明朝那些事儿》？</a></p>
<p><a href="https://mp.weixin.qq.com/s/-65DhkgUv0cUCgYbro67MQ" target="_blank" rel="noopener">周末推荐几个好用的免费在线看电影网站</a></p>
<p><a href="https://mp.weixin.qq.com/s/FzccdcMol_DYQhUMPgbdyg" target="_blank" rel="noopener">双十一防虚假促销套路，先查询下商品历史价格</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a></p>
<p>好，下面开始说重点了，之前双十一在知识星球和微信群里发了次抽奖，就是抽一个66.66现金。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-0377b12053fd4610.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"><br>然后微信群友 没见过鱼的北方人 喜中了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-3b68b0c7095f8cfe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>我建议他去买个彩票。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-4140b6781f6130e7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>好了，下面就是今天的<code>活动抽奖</code>，抽8人每人18元现金红包，开奖后可以直接提现到微信秒到账，下面是我昨天提现的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-7c72c5fd15f737bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2e459ddbcf74b87a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-ae1fea002f63080b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>邀请好友还能增加中奖率。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-ac2585c461a14fbc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p> 另外在<a href="https://mp.weixin.qq.com/s/1yAoLgsaPolKvrM6ZIzxvA" target="_blank" rel="noopener">本公众号文章下面留言</a>，点赞数前10，每人6.6现金红包（加我微信发送，截止时间11月17号20点）。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-980ad3ca4ef403c9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-fc93ea475920fa3f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-6c17b67c5b86d015.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/27/现在做公众号还赚钱吗？辛苦坚持2个月才赚了120/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/27/现在做公众号还赚钱吗？辛苦坚持2个月才赚了120/" itemprop="url">现在做公众号还赚钱吗？辛苦坚持2个月才赚了120</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-27T20:19:46+08:00">
                2019-11-27
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  451 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>话说现在几乎人手一个公众号了，我的号很早就开通了，但一直没怎么运营过，如果不是这次微信把流量主门槛从5000降低到500，可能我都没有动力继续更新。</p>
<p>微信把门槛放低了，所以为了赚钱（就是这么实在，大家也都这样吧，哈哈），我保持每周至少更新2篇文章，从5月开始到现在，已发布20篇文章。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-61798bc4c7b63fd2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-35b365184a4c7d58.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-6b5fdca5bbe87010.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2fab0200dbfd531d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>其中17篇为原创，奇技淫巧系列是我耗费时间最多，也认为写的最好的文章。</p>
<p><a href="https://mp.weixin.qq.com/s/R3x-xZwqLIVwPjlgikDQ9A" target="_blank" rel="noopener">那些你可能不知道的免费观看 VIP 视频奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/-cSjrvkibYGp5Fx8gCTFuw" target="_blank" rel="noopener">那些你可能不知道的浏览器奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/j7VhoZXmUTnOWC5C_B8jlQ" target="_blank" rel="noopener">那些你可能不知道的微博奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/LtI2piwAIDXA590NEsXvuw" target="_blank" rel="noopener">那些你可能不知道的网易云音乐奇技淫巧</a></p>
<p> <a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483979&amp;idx=1&amp;sn=0735daa1d805b66d346ed0e8e60a841f&amp;scene=21#wechat_redirect" target="_blank" rel="noopener">那些你可能不知道的搜索奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s?__biz=MzIyMjg2ODExMA==&amp;mid=2247483983&amp;idx=1&amp;sn=f0e1d9a8e22caf609d6c21431a530186&amp;chksm=e827a5aedf502cb8b72f2036054753fcfd9c20c28b9fbccdeae619a254a80e1024f18ba06523&amp;token=457023358&amp;lang=zh_CN#rd" target="_blank" rel="noopener">那些你可能不知道的视频下载奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/sqRgMh4rxFBt5YxNtaa6dw" target="_blank" rel="noopener">那些你可能不知道的知乎奇技淫巧</a></p>
<p>终于功夫不负有心人，6月底的时候有人找上我来投放广告。</p>
<p>是一个叫万门大学的教育机构，他们只给了120，虽然很少，但至少是个好的开始,于是我就接下了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e0a37f1d3a3ad87c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-18f5eb5709721703.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>文章给对方预览好后还没推送就到账了，果然很实诚。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-e35f8d5491d6878c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>于是我就推送了第一个公众号广告，就是这篇文章了 。<br><a href="https://mp.weixin.qq.com/s/bHVbEoIPVu2y_npb9wo_Wg" target="_blank" rel="noopener">我们计划招收300名学员，免费攻读人工智能专业</a></p>
<p> 公众号的红利期已经过去，你还在坚持写公众号吗？</p>
<p>ps:不知道除了接广告，大家还有什么途径赚钱的。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/26/周星驰电影全集分享/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/26/周星驰电影全集分享/" itemprop="url">周星驰电影全集分享</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-26T20:36:35+08:00">
                2019-11-26
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  468 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  1 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>周星驰，从星仔到星爷，如雷贯耳，当之无愧的喜剧之王，相信不用多介绍了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-e521db70d33b93f1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<blockquote>
<p>1990年凭借喜剧片《一本漫画闯天涯》确立其无厘头的表演风格   ；同年，因其主演的喜剧动作片《赌圣》打破香港地区票房纪录而获得关注   。1991年主演喜剧片《逃学威龙》，并再次打破香港地区票房纪录   。1995年凭借喜剧爱情片《大话西游》奠定其在华语影坛的地位。1999年自导自演的喜剧片《喜剧之王》获得香港电影年度票房冠军  。</p>
</blockquote>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-18577b7f2ff6d716.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>参演电影都是经典之作<a href="https://movie.douban.com/celebrity/1048026/" target="_blank" rel="noopener">https://movie.douban.com/celebrity/1048026/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-cd9d2edc1def2740.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>很多电影陪伴了我枯燥的中学生涯，感谢星爷这些作品，这里也给大家分享下他曾经的那些代表作。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-f5d25eb5a8b82831.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-f2bf3a683720a609.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-581932db119bd8b2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-11f9045d75520ac9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>公众号回复 <code>周星驰</code> 获取电影，包括《唐伯虎点秋香》《功夫》《百变星君》《整蛊专家》《大话西游》《喜剧之王》《鹿鼎记》《国产凌凌漆》《鹿鼎记》《大内密探零零发》《少林足球》《逃学威龙系列》等几十倍电影。</p>
<p>另外发个福利，无套路现金红包抽奖 ，抽8人每人18元现金红包，开奖后可以直接提现到微信秒到账。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-36571ffdb3b80fb2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-e3710782eb76d5d7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/RWxn4_Qg_Z3bL4wKusndKA" target="_blank" rel="noopener">不会写Python代码如何抓取豆瓣电影 Top 250</a></p>
<p><a href="https://mp.weixin.qq.com/s/whcZis69KnIzEUVMtrjdmA" target="_blank" rel="noopener">Python 词云分析周杰伦新歌《说好不哭》</a></p>
<p><a href="https://mp.weixin.qq.com/s/FzccdcMol_DYQhUMPgbdyg" target="_blank" rel="noopener">双十一防虚假促销套路，先查询下商品历史价格</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/21/那些我关注的-b-站-up-主/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/21/那些我关注的-b-站-up-主/" itemprop="url">那些我关注的 b 站 up 主</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-21T20:26:40+08:00">
                2019-11-21
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  907 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  3 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>关于b站之前写过 <a href="https://mp.weixin.qq.com/s/HpuInXUCjSYT7HLqhoRcCA" target="_blank" rel="noopener">那些你可能不知道的 bilibili 奇技淫巧</a> ，b站是我每天都要逛的网站，也关注了不少有趣的up主，这里做个整理。那些比较知名的up主，如《李子柒》《电影最Top》《野食小哥》《我是郭杰瑞》《木鱼水心》《李永乐老师》这些百万up主就不说了。</p>
<h3 id="大象放映室"><a href="#大象放映室" class="headerlink" title="大象放映室"></a>大象放映室</h3><p>解说电影up主，b站主页 <a href="https://space.bilibili.com/49246269/" target="_blank" rel="noopener">https://space.bilibili.com/49246269/</a>  女主播声音很好听。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c1c186630726c966.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>虽然发布的视频不多，但都是精品，比如章子怡的《我的父亲母亲》，李安《少年派》。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-39e30a43f7ad9c38.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>类似的电影解说up主还有 电影talks <a href="https://space.bilibili.com/319751089/" target="_blank" rel="noopener">https://space.bilibili.com/319751089/</a> </p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-d076430d9be7878c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>影视摆渡人 <a href="https://space.bilibili.com/386002045/" target="_blank" rel="noopener">https://space.bilibili.com/386002045/</a> 这位up主解说的段奕宏，俞飞鸿电影《爱有来生》太唯美了（公众号回复<code>爱有来生</code>获取电影），文字功底太强了 <a href="https://www.bilibili.com/video/av73324690" target="_blank" rel="noopener">https://www.bilibili.com/video/av73324690</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-6d20c303267f4732.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-cdb88082abd71414.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="回形针"><a href="#回形针" class="headerlink" title="回形针"></a>回形针</h3><p>回形针PaperClip，你的当代生活说明书，b站主页 <a href="https://space.bilibili.com/258150656/" target="_blank" rel="noopener">https://space.bilibili.com/258150656/</a>  ，发布各种科普视频，比如手机充电为什么这么慢，买彩票一定亏吗？<br><img src="https://upload-images.jianshu.io/upload_images/17817191-f571ea473ee886b7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>他们还有一个百科全书性质的网站  <a href="https://ipaperclip.net/" target="_blank" rel="noopener">https://ipaperclip.net/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-941b9d00cbde6a34.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>最近还发布一个第一百期节目的解密游戏<a href="https://www.bilibili.com/video/av75572775" target="_blank" rel="noopener">https://www.bilibili.com/video/av75572775</a> ，知乎回答<a href="https://www.zhihu.com/question/355722223/answer/893812403" target="_blank" rel="noopener">https://www.zhihu.com/question/355722223/answer/893812403</a></p>
<h3 id="柴知道"><a href="#柴知道" class="headerlink" title="柴知道"></a>柴知道</h3><p>知识科普up主，带你在知识的海洋里狗刨，b站主页<a href="https://space.bilibili.com/26798384/" target="_blank" rel="noopener">https://space.bilibili.com/26798384/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-16a227389b204170.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>主要发布那些你不知道的知识的科普视频。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-eec631233570086a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="汤质看本质"><a href="#汤质看本质" class="headerlink" title="汤质看本质"></a>汤质看本质</h3><p>这是一个让你感觉自己一无所知的up主，视频有点烧脑，b站主页<a href="https://space.bilibili.com/362588980/" target="_blank" rel="noopener">https://space.bilibili.com/362588980/</a> 。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-ff6be621754db110.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="man影君"><a href="#man影君" class="headerlink" title="man影君"></a>man影君</h3><p>战争电影剪辑up主，发布了近400个战争电影，b站主页<a href="https://space.bilibili.com/327567693/" target="_blank" rel="noopener">https://space.bilibili.com/327567693/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-0f86053ca10a0325.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="冒险雷探长"><a href="#冒险雷探长" class="headerlink" title="冒险雷探长"></a>冒险雷探长</h3><p>《冒险雷探长》一档环球探索纪录片，走访失落的古迹，探索人类未解之谜，比如他最近更新的叙利亚视频，b站主页<a href="https://space.bilibili.com/49494871" target="_blank" rel="noopener">https://space.bilibili.com/49494871</a> 。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5395ae30aa059492.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>非洲食人族视频<br><img src="https://upload-images.jianshu.io/upload_images/17817191-5201c346f6dcae30.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="窟眩视频"><a href="#窟眩视频" class="headerlink" title="窟眩视频"></a>窟眩视频</h3><p>自制全面战争记录片up主，战火与文明，杀戮与止战，古战场的恢宏攻伐，独特视角给您重现古战场，比如 山海关之战，楚汉风云，巨鹿之战等，b站主页 <a href="https://space.bilibili.com/5150024/video" target="_blank" rel="noopener">https://space.bilibili.com/5150024/video</a> ，遗憾的是up主很久不更新了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-21d9d44a3784e783.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<h3 id="Runa-涉谷瑠菜"><a href="#Runa-涉谷瑠菜" class="headerlink" title="Runa-涉谷瑠菜"></a>Runa-涉谷瑠菜</h3><p>一个在中国留学的日本妹子up主，主要发布在中国的一些趣闻，声音很好听，b站主页<a href="https://space.bilibili.com/456917891/" target="_blank" rel="noopener">https://space.bilibili.com/456917891/</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-814b865b98d6619f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>最后如果你想下载b站视频，公众号回复 <code>b站</code>获取工具。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-cc053de1e74ce949.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>你关注了哪些有趣的up主，可以留言推荐下 ，我也关注一波。</p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>是落拓呀 <a href="https://space.bilibili.com/43276908/" target="_blank" rel="noopener">https://space.bilibili.com/43276908/</a><br>梦回大明三百年 <a href="https://space.bilibili.com/66384210/" target="_blank" rel="noopener">https://space.bilibili.com/66384210/</a><br>超钱思维<a href="https://space.bilibili.com/271553616/" target="_blank" rel="noopener">https://space.bilibili.com/271553616/</a><br>幻想浅绿 <a href="https://space.bilibili.com/1424972/" target="_blank" rel="noopener">https://space.bilibili.com/1424972/</a><br>你在b站关注了哪些惊为天人的up主？ <a href="https://www.weibo.com/3305085281/IfYVr44kt" target="_blank" rel="noopener">https://www.weibo.com/3305085281/IfYVr44kt</a><br>电影不烧口 <a href="https://space.bilibili.com/84782178/" target="_blank" rel="noopener">https://space.bilibili.com/84782178/</a><br>越哥说电影 <a href="https://space.bilibili.com/149558293/" target="_blank" rel="noopener">https://space.bilibili.com/149558293/</a><br> ​​​​</p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/RWxn4_Qg_Z3bL4wKusndKA" target="_blank" rel="noopener">不会写Python代码如何抓取豆瓣电影 Top 250</a></p>
<p><a href="https://mp.weixin.qq.com/s/whcZis69KnIzEUVMtrjdmA" target="_blank" rel="noopener">Python 词云分析周杰伦新歌《说好不哭》</a></p>
<p><a href="https://mp.weixin.qq.com/s/FzccdcMol_DYQhUMPgbdyg" target="_blank" rel="noopener">双十一防虚假促销套路，先查询下商品历史价格</a></p>
<p><a href="https://mp.weixin.qq.com/s/f36fXJbMYgWMTSTaGMeFCg" target="_blank" rel="noopener">比谷歌更有意思的知识提取搜索引擎 magi</a></p>
<p><a href="https://mp.weixin.qq.com/s/I6Cd01c9fDx3MFeE3pGauw" target="_blank" rel="noopener">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/20/php-开发记录/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/20/php-开发记录/" itemprop="url">php 开发记录</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-20T11:19:09+08:00">
                2019-11-20
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  14.5k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  69 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h3 id="错误处理"><a href="#错误处理" class="headerlink" title="错误处理"></a>错误处理</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    $a = <span class="number">5</span> / <span class="number">0</span>;</span><br><span class="line">&#125; <span class="keyword">catch</span> (Exception $e) &#123;</span><br><span class="line">    $e-&gt;getMessage();</span><br><span class="line">    $a = <span class="number">-1</span>;  <span class="comment">// 通过异常来处理 $a 为 0 的情况，但是实际上，捕获不到该异常</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">echo $a;</span><br><span class="line"><span class="comment">// PHP Warning:  Division by zero</span></span><br><span class="line">PHP7 开始统一这两者，使错误也可以像异常那样抛出</span><br><span class="line">PHP 中的错误可理解为 使脚本不运行不正常的情况，根据错误级别从高到低可划分为五类</span><br><span class="line"></span><br><span class="line">Parse error 或 Syntax <span class="built_in">Error</span> - 语法解析错误，触发该错误后，脚本完全无法运行；</span><br><span class="line">Fatal <span class="built_in">Error</span> - 致命错误，触发该错误后，后面的脚本无法继续执行；</span><br><span class="line">Warning <span class="built_in">Error</span> - 出现比较不恰当的地方，脚本可继续执行；</span><br><span class="line">Notice <span class="built_in">Error</span> - 出现不恰当的地方，但是程度比 Warning <span class="built_in">Error</span> 低，脚本可继续执行；</span><br><span class="line">Deprecated <span class="built_in">Error</span> - 不推荐这么使用，未来可能会废弃，脚本可继续执行；</span><br><span class="line"><span class="comment">// E_ALL - 处理全部错误类型</span></span><br><span class="line">set_error_handler(<span class="string">'customError'</span>, E_ALL);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @param  int $errno 错误的级别</span></span><br><span class="line"><span class="comment"> * @param  string $errstr  错误的信息</span></span><br><span class="line"><span class="comment"> * @param  string $errfile 错误的文件名(可选)</span></span><br><span class="line"><span class="comment"> * @param  string $errline 错误发生的行号（可选）</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">customError</span>(<span class="params">int $errno, string $errstr, string $errfile, string $errline</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    echo sprintf(<span class="string">'错误消息为 %s'</span>, $errstr);</span><br><span class="line">&#125;</span><br><span class="line">当错误类型为 E_USER_DEPRECATED 时，需要添加 @</span><br><span class="line"></span><br><span class="line">@trigger_error(<span class="string">"foo"</span>, E_USER_DEPRECATED);</span><br><span class="line">$a = <span class="number">5</span> / <span class="number">0</span>;  <span class="comment">// 错误消息为 Division by zero</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">division</span>(<span class="params">$a, $b</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span>($b == <span class="number">0</span>)&#123;</span><br><span class="line">        @trigger_error(<span class="string">"0 不能作为除数"</span>, E_USER_NOTICE);</span><br><span class="line">        <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $a / $b;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">echo division(<span class="number">10</span>, <span class="number">0</span>);</span><br><span class="line">开发环境推荐配置</span><br><span class="line"></span><br><span class="line">display_errors = On</span><br><span class="line">display_startup_error = On</span><br><span class="line">error_reporting = <span class="number">-1</span></span><br><span class="line">log_errors = On</span><br><span class="line">生产环境推荐配置</span><br><span class="line"></span><br><span class="line">display_errors = Off</span><br><span class="line">display_startup_error = Off</span><br><span class="line">; 报告 Notice 以外的所有错误</span><br><span class="line">error_reporting = E_ALL &amp; ~E_NOTICE</span><br><span class="line">log_errors = On</span><br><span class="line">https:<span class="comment">//learnku.com/articles/36521</span></span><br></pre></td></tr></table></figure>
<h3 id="对象的浅拷贝与深拷贝"><a href="#对象的浅拷贝与深拷贝" class="headerlink" title="对象的浅拷贝与深拷贝"></a>对象的浅拷贝与深拷贝</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Bar</span> </span>&#123;</span><br><span class="line">    public $name;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span> </span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public $bar;</span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;bar = <span class="keyword">new</span> Bar();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$foo = <span class="keyword">new</span> Foo();</span><br><span class="line">$copyFoo = clone $foo;</span><br><span class="line"></span><br><span class="line">var_dump($foo-&gt;bar === $copyFoo-&gt;bar);  <span class="comment">// bool(true)</span></span><br><span class="line">克隆的实例与原有的实例的 bar 成员都指向同一个实例 https:<span class="comment">//github.com/myclabs/DeepCopy</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/36876</span></span><br></pre></td></tr></table></figure>
<h3 id="php数组"><a href="#php数组" class="headerlink" title="php数组"></a>php数组</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br></pre></td><td class="code"><pre><span class="line">其他编程语言数组是由相同类型的元素（element）的集合所组成的数据结构，而 PHP 数组元素可以为不同类型的元素。因此说 PHP 数组不是纯粹的数组，而是哈希 (字典) 更为恰当.</span><br><span class="line">注意的是字符串类型假如是有效十进制数字的话，则会转换为整型. <span class="string">"8"</span>-&gt;<span class="number">8.</span> 若不想转换则在数字前添加 <span class="string">"+"</span> 符号.</span><br><span class="line"></span><br><span class="line"><span class="comment">// 02不是有效十进制数字</span></span><br><span class="line">$arr = [<span class="string">'1'</span> =&gt; <span class="string">'a'</span>, <span class="string">'+1'</span> =&gt; <span class="string">'b'</span>, <span class="string">'02'</span> =&gt; <span class="string">'c'</span>];</span><br><span class="line">(array)$scalarValue 与 array ($scalarValue) 一样。而对象 (object) 类型转换为 array. 其单元为该对象的属性。键名将为成员变量名，不过有几点例外：整数属性不可访问；私有变量前会加上类名作前缀；保护变量前会加上一个 <span class="string">'*'</span> 做前缀。这些前缀的前后都各有一个 NULL 字符。</span><br><span class="line">var_dump(array_fill(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>)); <span class="comment">// []</span></span><br><span class="line">var_dump(array_fill(<span class="number">1</span>, <span class="number">3</span>, <span class="string">'red'</span>)); <span class="comment">// [1=&gt;'red', 2=&gt;'red', 3=&gt;'red']</span></span><br><span class="line">$a = [<span class="string">'a'</span> =&gt; <span class="number">1</span>, <span class="string">'B'</span> =&gt; <span class="number">2</span>, <span class="number">3</span> =&gt; <span class="string">'c'</span>, <span class="string">'A'</span> =&gt; <span class="number">4</span>, <span class="string">'b'</span> =&gt; <span class="number">6</span>];</span><br><span class="line">print_r(array_chunk($a, <span class="number">2</span>)); <span class="comment">// [[1, 2], ['c', 4], [6]]</span></span><br><span class="line">print_r(array_chunk($a, <span class="number">2</span>, <span class="literal">true</span>)); <span class="comment">// [['a' =&gt; 1, 'B' =&gt; 2], [3 =&gt; 'c', 'A' =&gt; 4], ['b' =&gt; 6]]</span></span><br><span class="line"></span><br><span class="line">var_dump(array_slice($a, <span class="number">-1</span>, <span class="number">1</span>, <span class="literal">true</span>)); [<span class="number">4</span> =&gt; <span class="string">'f'</span>]</span><br><span class="line"></span><br><span class="line">print_r(array_count_value([<span class="number">1</span>, <span class="string">'hello'</span>, <span class="number">1</span>, <span class="string">'hello'</span>, <span class="string">'world'</span>])) <span class="comment">// [1=&gt;2, 'hello' =&gt; 2, 'world' =&gt; 1]</span></span><br><span class="line">var_dump(array_product([])); <span class="comment">// 1</span></span><br><span class="line">var_dump(array_sum([])); <span class="comment">// 0</span></span><br><span class="line">$a = [<span class="string">'a'</span> =&gt; <span class="number">1</span>, <span class="string">'b'</span> =&gt; <span class="number">2</span>, <span class="string">'c'</span> =&gt; <span class="number">3</span>];</span><br><span class="line">var_dump(array_keys($a)); <span class="comment">// ['a', 'b', 'c']</span></span><br><span class="line">var_dump(array_keys($a, <span class="string">'1'</span>)); <span class="comment">// 'a'</span></span><br><span class="line">var_dump(array_keys($a, <span class="string">'1'</span>, <span class="literal">true</span>)); <span class="comment">// []</span></span><br><span class="line">var_dump(array_rand([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>], <span class="number">2</span>)); <span class="comment">// [1, 3]</span></span><br><span class="line">var_dump(array_search(<span class="literal">false</span>, $a, <span class="literal">true</span>)); <span class="comment">// false</span></span><br><span class="line">var_dump(in_array(<span class="string">'1'</span>, $os, <span class="literal">true</span>)); <span class="comment">// false</span></span><br><span class="line">var_dump(array_diff($array1, $array2, $array3)); <span class="comment">// ['blue']</span></span><br><span class="line"></span><br><span class="line">$arr1 = [<span class="string">'color'</span> =&gt; [<span class="string">'favorite'</span> =&gt; <span class="string">'red'</span>, <span class="number">5</span>]];</span><br><span class="line">$arr2 = [<span class="string">'color'</span> =&gt; [<span class="string">'favorite'</span> =&gt; <span class="string">'green'</span>, <span class="number">6</span>, <span class="number">7</span>]];</span><br><span class="line">var_dump(array_merge_recursive($arr1, $arr2)); <span class="comment">// ['color' =&gt; ['favorite' =&gt; ['red', 'green'], 5, 6, 7]]</span></span><br><span class="line">$arr1 = [<span class="string">'color'</span> =&gt; [<span class="string">'favorite'</span> =&gt; <span class="string">'red'</span>, <span class="number">5</span>]];</span><br><span class="line">$arr2 = [<span class="string">'color'</span> =&gt; [<span class="string">'favorite'</span> =&gt; <span class="string">'green'</span>, <span class="number">6</span>, <span class="number">7</span>]];</span><br><span class="line">var_dump(array_merge($arr1, $arr2)); <span class="comment">// ['color' =&gt; ['favorite' =&gt; 'green', 6, 7]];</span></span><br><span class="line">var_dump($arr1 + $arr2); <span class="comment">// ['color' =&gt; ['favorite' =&gt; 'red', 5]]</span></span><br><span class="line">$ar1 = [<span class="number">10</span>, <span class="number">100</span>, <span class="number">100</span>, <span class="number">0</span>];</span><br><span class="line">$ar2 = [<span class="number">1</span>, <span class="number">3</span>, <span class="number">2</span>, <span class="number">4</span>];</span><br><span class="line">array_multisort($ar1, $ar2); <span class="comment">// [0, 10, 100, 100] [4, 1, 2, 3]</span></span><br><span class="line">array_multisort($ar1, SORT_DESC, SORT_NUMERIC, $ar2, SORT_ASC, SORT_NUMERIC); <span class="comment">// [100, 100, 10, 0] [2, 3, 1, 4]</span></span><br><span class="line"><span class="comment">// 排序针对的是值, 而且会保存原先索引</span></span><br><span class="line">$fruits = array(<span class="string">"d"</span> =&gt; <span class="string">"lemon"</span>, <span class="string">"a"</span> =&gt; <span class="string">"orange"</span>, <span class="string">"b"</span> =&gt; <span class="string">"banana"</span>, <span class="string">"c"</span> =&gt; <span class="string">"apple"</span>);</span><br><span class="line">arsort($fruits);</span><br><span class="line">print_r($fruits); <span class="comment">// ['a' =&gt; 'orange', 'd' =&gt; 'lemon', 'b' =&gt; 'banana', 'c' =&gt; 'apple']</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 语言结构, 并非函数</span></span><br><span class="line">$info = [<span class="string">'coffee'</span>, <span class="string">'brown'</span>, <span class="string">'caffeine'</span>];</span><br><span class="line">list($drink, $color, $power) = $info;</span><br><span class="line">echo <span class="string">"$drink, $color, $power"</span>; <span class="comment">// coffee, brown, caffeine</span></span><br><span class="line"><span class="comment">// 可以省略不想取的</span></span><br><span class="line">list($drink, , $power) = $info;</span><br><span class="line">echo <span class="string">"$drink, $power"</span>; <span class="comment">// coffee, caffeine</span></span><br><span class="line"><span class="comment">// 7.0 以上是从左到右赋值, 7.0以下是从右到左赋值</span></span><br><span class="line">list($a[<span class="number">0</span>], $a[<span class="number">1</span>], $a[<span class="number">2</span>]) = $info;</span><br><span class="line"><span class="comment">// 7.0 以上</span></span><br><span class="line">var_dump($a); <span class="comment">// ['coffee', 'brown', 'caffeine']</span></span><br><span class="line"><span class="comment">// 7.0 以下</span></span><br><span class="line">var_dump($a); <span class="comment">// ['caffeine', 'brown', 'coffee']</span></span><br><span class="line"><span class="comment">// 7.1 支持索引数组</span></span><br><span class="line">$info = [<span class="string">'a'</span> =&gt; <span class="string">'coffee'</span>, <span class="string">'b'</span> =&gt; <span class="string">'brown'</span>, <span class="string">'c'</span> =&gt; <span class="string">'caffeine'</span>];</span><br><span class="line">list(<span class="string">'a'</span> =&gt; $drink, <span class="string">'c'</span> =&gt; $power) = $info;</span><br><span class="line">echo <span class="string">"$drink, $power"</span>; <span class="comment">// coffee, caffeine</span></span><br><span class="line">$a = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>];</span><br><span class="line">echo count($a); <span class="comment">// 3</span></span><br><span class="line">$b = [$a, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>];</span><br><span class="line">echo count($b, COUNT_RECURSIVE) <span class="comment">// 7</span></span><br><span class="line"></span><br><span class="line">$a = [<span class="string">'php'</span>, <span class="number">4.0</span>, [<span class="string">'green'</span>, <span class="string">'red'</span>]];</span><br><span class="line">var_dump(array_reverse($a)); <span class="comment">// [['green', 'red'], 7.1, 'php']</span></span><br><span class="line">var_dump(array_reverse($a, <span class="literal">true</span>)); <span class="comment">// [2 =&gt; ['green', 'red'], 1 =&gt; 7.1, 0 =&gt; 'php']</span></span><br><span class="line"></span><br><span class="line">$sweet = [<span class="string">'a'</span> =&gt; <span class="string">'apple'</span>, <span class="string">'b'</span> =&gt; <span class="string">'banana'</span>];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">testPrint</span>(<span class="params">$item, $key, $userData</span>) </span>&#123;</span><br><span class="line">  echo <span class="string">"$key holds $item and $userData\n"</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">* a holds apple and php</span></span><br><span class="line"><span class="comment">* b holds banana and php</span></span><br><span class="line"><span class="comment">* sour holds lemon and php</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line">array_walk_recursive($fruits, <span class="string">'testPrint'</span>, <span class="string">'php'</span>);</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">odd</span>(<span class="params">$var</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">return</span> $<span class="keyword">var</span> &amp; <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 自然排序, 以人们认知方式排序,区分大小写</span></span><br><span class="line">$arr = [<span class="string">'a1'</span>, <span class="string">'A1'</span>, <span class="string">'c2'</span>, <span class="string">'c3'</span>, <span class="string">'b4'</span>, <span class="string">'b5'</span>, <span class="string">'B1'</span>];</span><br><span class="line">natsort($arr);  <span class="comment">// true</span></span><br><span class="line">var_dump($arr); <span class="comment">// ['A1', 'B1', 'a1', 'b4', 'b5', 'c2', 'c3']</span></span><br><span class="line"><span class="comment">// 数字比较项目, 'a1' 转换数字为 0, 所以排序顺序如下</span></span><br><span class="line">$arr1 = [<span class="string">'a1'</span>, <span class="number">0</span>, <span class="number">2</span>, <span class="string">'1a'</span>];</span><br><span class="line">sort($arr1, SORT_NUMERIC);</span><br><span class="line">var_dump($arr1);  <span class="comment">// ['a1', 0, '1a', 2]</span></span><br><span class="line"><span class="comment">// 被作为字符串来比较</span></span><br><span class="line">$fruits = array(<span class="string">"lemon"</span>, <span class="string">"orange"</span>, <span class="string">"banana"</span>, <span class="string">"apple"</span>, <span class="number">1</span>);</span><br><span class="line">sort($fruits, SORT_STRING);</span><br><span class="line">var_dump($fruits); <span class="comment">// [1, 'apple', 'banana', 'lemon', 'orange']</span></span><br><span class="line"><span class="comment">//  和 natsort() 类似对每个单元以“自然的顺序”对字符串进行排序</span></span><br><span class="line">$arr = [<span class="string">'a1'</span>, <span class="string">'A1'</span>, <span class="string">'c2'</span>, <span class="string">'c3'</span>, <span class="string">'b4'</span>, <span class="string">'b5'</span>, <span class="string">'B1'</span>];</span><br><span class="line">sort($arr, SORT_NATURAL);  <span class="comment">// true</span></span><br><span class="line">var_dump($arr); <span class="comment">// ['A1', 'B1', 'a1', 'b4', 'b5', 'c2', 'c3']</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/36866</span></span><br></pre></td></tr></table></figure>
<h3 id="Base64-加密算法"><a href="#Base64-加密算法" class="headerlink" title="Base64 加密算法"></a>Base64 加密算法</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//gitee.com/obamajs/php-base64-implemention/blob/master/Base64.php</span></span><br><span class="line">base64 的作用是把任意的字符序列转换为只包含特殊字符集的序列</span><br><span class="line">每个 Base64 字符用 <span class="number">6</span> 位来表示，但是一个字节是 <span class="number">8</span> 位，所以 <span class="number">3</span> 个字节刚好可以生成 <span class="number">4</span> 个 Base64 字符，这应该很容易计算出来，下面我给大家举个例子，假如说现在有个字符串为 <span class="string">"123"</span>，<span class="number">1</span> 的 ASCII 为 <span class="number">49</span>，那么转换为二进制就是 <span class="number">00110001</span>，<span class="number">2</span> 的 ASCII 为 <span class="number">50</span>，那么转换为二进制就是 <span class="number">00110010</span>，<span class="number">3</span> 的 ASCII 为 <span class="number">51</span>，那么转换为二进制就是 <span class="number">00110011</span>，这三个二进制组合在一起就是这样：<span class="number">001100010011001000110011</span></span><br><span class="line">按照 <span class="number">4</span> 个 Base64 字符转换为 <span class="number">3</span> 个 <span class="number">8</span> 位的字节算法就可以了，<span class="number">4</span> 个字符组合起来就是 <span class="number">24</span> 位，按照 <span class="number">8</span> 位一个字节，就是三个字节。</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">normalToBase64Char</span>(<span class="params">$num</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> ($num &gt;= <span class="number">0</span> &amp;&amp; $num &lt;= <span class="number">25</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> chr(ord(<span class="string">'A'</span>) + $num);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($num &gt;= <span class="number">26</span> &amp;&amp; $num &lt;= <span class="number">51</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> chr(ord(<span class="string">'a'</span>) + ($num - <span class="number">26</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($num &gt;= <span class="number">52</span> &amp;&amp; $num &lt;= <span class="number">61</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> chr(ord(<span class="string">'0'</span>) + ($num - <span class="number">52</span>));</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($num == <span class="number">62</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">'+'</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">'/'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">base64CharToInt</span>(<span class="params">$num</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span> ($num &gt;= <span class="number">65</span> &amp;&amp; $num &lt;= <span class="number">90</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> ($num - <span class="number">65</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($num &gt;= <span class="number">97</span> &amp;&amp; $num &lt;= <span class="number">122</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> ($num - <span class="number">97</span>) + <span class="number">26</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($num &gt;= <span class="number">48</span> &amp;&amp; $num &lt;= <span class="number">57</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> ($num - <span class="number">48</span>) + <span class="number">52</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> ($num == <span class="number">43</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">62</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">63</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/36655</span></span><br></pre></td></tr></table></figure>
<h3 id="一致性-hash-算法"><a href="#一致性-hash-算法" class="headerlink" title="一致性 hash 算法"></a>一致性 hash 算法</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 一致性哈希算法</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ConsistentHashing</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    protected $nodes = array();    <span class="comment">//真实节点</span></span><br><span class="line">    protected $position = array();  <span class="comment">//虚拟节点</span></span><br><span class="line">    protected $mul = <span class="number">64</span>;  <span class="comment">// 每个节点对应64个虚拟节点</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 把字符串转为32位符号整数</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">hash</span>(<span class="params">$str</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> sprintf(<span class="string">'%u'</span>, crc32($str));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 核心功能</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">lookup</span>(<span class="params">$key</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $point = $<span class="keyword">this</span>-&gt;hash($key);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//先取圆环上最小的一个节点,当成结果</span></span><br><span class="line">        $node = current($<span class="keyword">this</span>-&gt;position);</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 循环获取相近的节点</span></span><br><span class="line">        foreach ($<span class="keyword">this</span>-&gt;position <span class="keyword">as</span> $key =&gt; $val) &#123;</span><br><span class="line">            <span class="keyword">if</span> ($point &lt;= $key) &#123;</span><br><span class="line">                $node = $val;</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        reset($<span class="keyword">this</span>-&gt;position);    <span class="comment">//把数组的内部指针指向第一个元素，便于下次查询从头查找</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $node;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 添加节点</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">addNode</span>(<span class="params">$node</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(isset($<span class="keyword">this</span>-&gt;nodes[$node])) <span class="keyword">return</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 添加节点和虚拟节点</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $<span class="keyword">this</span>-&gt;mul; $i++) &#123;</span><br><span class="line">            $pos = $<span class="keyword">this</span>-&gt;hash($node . <span class="string">'-'</span> . $i);</span><br><span class="line">            $<span class="keyword">this</span>-&gt;position[$pos] = $node;</span><br><span class="line">            $<span class="keyword">this</span>-&gt;nodes[$node][] = $pos;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 重新排序</span></span><br><span class="line">        $<span class="keyword">this</span>-&gt;sortPos();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 删除节点</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">delNode</span>(<span class="params">$node</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (!isset($<span class="keyword">this</span>-&gt;nodes[$node])) <span class="keyword">return</span>;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 循环删除虚拟节点</span></span><br><span class="line">        foreach ($<span class="keyword">this</span>-&gt;nodes[$node] <span class="keyword">as</span> $val) &#123;</span><br><span class="line">            unset($<span class="keyword">this</span>-&gt;position[$val]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 删除节点</span></span><br><span class="line">        unset($<span class="keyword">this</span>-&gt;nodes[$node]);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 排序</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">sortPos</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        ksort($<span class="keyword">this</span>-&gt;position, SORT_REGULAR);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 测试</span></span><br><span class="line">$con = <span class="keyword">new</span> ConsistentHashing();</span><br><span class="line"></span><br><span class="line">$con-&gt;addNode(<span class="string">'a'</span>);</span><br><span class="line">$con-&gt;addNode(<span class="string">'b'</span>);</span><br><span class="line">$con-&gt;addNode(<span class="string">'c'</span>);</span><br><span class="line">$con-&gt;addNode(<span class="string">'d'</span>);</span><br><span class="line"></span><br><span class="line">$key1 = <span class="string">'www.zhihu.com'</span>;</span><br><span class="line">$key2 = <span class="string">'www.baidu.com'</span>;</span><br><span class="line">$key3 = <span class="string">'www.google.com'</span>;</span><br><span class="line">$key4 = <span class="string">'www.testabc.com'</span>;</span><br><span class="line"></span><br><span class="line">echo <span class="string">'key'</span> . $key1 . <span class="string">'落在'</span> . $con-&gt;lookup($key1) . <span class="string">'号节点上！&lt;br&gt;'</span>;</span><br><span class="line">echo <span class="string">'key'</span> . $key2 . <span class="string">'落在'</span> . $con-&gt;lookup($key2) . <span class="string">'号节点上！&lt;br&gt;'</span>;</span><br><span class="line">echo <span class="string">'key'</span> . $key3 . <span class="string">'落在'</span> . $con-&gt;lookup($key3) . <span class="string">'号节点上！&lt;br&gt;'</span>;</span><br><span class="line">echo <span class="string">'key'</span> . $key4 . <span class="string">'落在'</span> . $con-&gt;lookup($key4) . <span class="string">'号节点上！&lt;br&gt;'</span>;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/30269</span></span><br></pre></td></tr></table></figure>
<h3 id="异常处理"><a href="#异常处理" class="headerlink" title="异常处理"></a>异常处理</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    $a = <span class="number">5</span> % <span class="number">0</span>;</span><br><span class="line">&#125; <span class="keyword">catch</span> (Exception $e) &#123;</span><br><span class="line">    echo $e-&gt;getMessage();</span><br><span class="line">    $a = <span class="number">-1</span>;  <span class="comment">// 通过异常来处理 $a 为 0 的情况，但是实际上，捕获不到该异常</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">echo $a;  <span class="comment">// 无法执行</span></span><br><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    $a = <span class="number">5</span> % <span class="number">0</span>;</span><br><span class="line">    <span class="comment">// 注意，DivisionByZeroError 错误只能捕捉到 % 运算，无法捕捉 / 运算</span></span><br><span class="line">&#125; <span class="keyword">catch</span> (DivisionByZeroError $e) &#123;</span><br><span class="line">    echo $e-&gt;getMessage();</span><br><span class="line">    $a = <span class="number">-1</span>;  </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">echo $a; <span class="comment">// -1</span></span><br><span class="line">异常将错误处理与常规代码进行分离，能够让业务流程更加清晰。</span><br><span class="line"></span><br><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    <span class="comment">// 业务流程</span></span><br><span class="line">&#125; <span class="keyword">catch</span> (FileNotFoundException $e) &#123;</span><br><span class="line"></span><br><span class="line">&#125; <span class="keyword">catch</span> (FileTypeException $e) &#123;</span><br><span class="line"></span><br><span class="line">&#125; <span class="keyword">catch</span> (Exception $e) &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 只处理 404 异常</span></span><br><span class="line">public <span class="function"><span class="keyword">function</span> <span class="title">actionType</span>(<span class="params">$username</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        $user = $client-&gt;get(sprintf(<span class="string">"/api/user/%s"</span>, $username));</span><br><span class="line">    &#125; <span class="keyword">catch</span> (RequestException $e) &#123;</span><br><span class="line">        <span class="keyword">if</span> (<span class="number">404</span> === $e-&gt;getResponse()-&gt;getStatusCode()) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">"create"</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">throw</span> $e;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> <span class="string">"update"</span>;</span><br><span class="line">&#125;</span><br><span class="line">set_exception_handler(<span class="function"><span class="keyword">function</span>(<span class="params">$exception</span>)</span>&#123;</span><br><span class="line">    echo <span class="string">'发生了未知错误'</span>;</span><br><span class="line">    log($exception-&gt;getMessage());</span><br><span class="line">&#125;);https:<span class="comment">//learnku.com/articles/37029</span></span><br></pre></td></tr></table></figure>
<h3 id="秒读-Excel-百万数据"><a href="#秒读-Excel-百万数据" class="headerlink" title="秒读 Excel 百万数据"></a>秒读 Excel 百万数据</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ReaderCsv</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 数组键值</span></span><br><span class="line"><span class="comment">     * @var int</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected $row = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Excel源数据</span></span><br><span class="line"><span class="comment">     * @var array</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected $excelData = [];</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 文件路径</span></span><br><span class="line"><span class="comment">     * @var</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    protected $path;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * ReaderCsv constructor.</span></span><br><span class="line"><span class="comment">     * @param $path</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$path</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;path = $path;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 读取CSV文件</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">readCsv</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">//数组键值</span></span><br><span class="line">        $row = $<span class="keyword">this</span>-&gt;row;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//Excel数组</span></span><br><span class="line">        $excelData = [];</span><br><span class="line"></span><br><span class="line">        <span class="comment">//打开文件</span></span><br><span class="line">        $file = fopen($<span class="keyword">this</span>-&gt;path, <span class="string">'r'</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//从文件指针中读入一行并解析 CSV 字段</span></span><br><span class="line">        <span class="comment">//fgetcsv 解析读入的行并找出 CSV 格式的字段然后返回一个包含这些字段的数组。</span></span><br><span class="line">        <span class="keyword">while</span> ($data = fgetcsv($file)) &#123;</span><br><span class="line">            <span class="comment">//统计一行数据有多少列</span></span><br><span class="line">            $columnSize = count($data);</span><br><span class="line"></span><br><span class="line">            <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $columnSize; $i++) &#123;</span><br><span class="line">                <span class="comment">//转换字符的编码 &amp;&amp; 赋值Excel源数据</span></span><br><span class="line">                $excelData[$row][$i] = mb_convert_encoding(</span><br><span class="line">                    $data[$i],</span><br><span class="line">                    <span class="string">'UTF-8'</span>,</span><br><span class="line">                    <span class="string">'gb2312'</span></span><br><span class="line">                );</span><br><span class="line">            &#125;</span><br><span class="line">            $row++;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $<span class="keyword">this</span>-&gt;row = $row;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//关闭一个已打开的文件指针</span></span><br><span class="line">        fclose($file);</span><br><span class="line"></span><br><span class="line">        $<span class="keyword">this</span>-&gt;excelData = $excelData;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取Excel源数据</span></span><br><span class="line"><span class="comment">     * @return array</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getExcelData</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;excelData;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 获取总行数</span></span><br><span class="line"><span class="comment">     * @return int</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">        public <span class="function"><span class="keyword">function</span> <span class="title">getRow</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;row;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//传入文件路径</span></span><br><span class="line">$readerCsv = <span class="keyword">new</span> ReaderCsv($filePath);</span><br><span class="line"></span><br><span class="line"><span class="comment">//读取csv文件</span></span><br><span class="line">$readerCsv-&gt;readCsv();</span><br><span class="line"></span><br><span class="line"><span class="comment">//获取Excel数据</span></span><br><span class="line">$excelData = $readerCsv-&gt;getExcelData();</span><br><span class="line">https:<span class="comment">//learnku.com/articles/37002</span></span><br><span class="line">https:<span class="comment">//phpspreadsheet.readthedocs.io/en/latest/</span></span><br><span class="line">https:<span class="comment">//github.com/rap2hpoutre/fast-excel</span></span><br><span class="line">https:<span class="comment">//github.com/viest/php-ext-xlswriter</span></span><br></pre></td></tr></table></figure>
<h3 id="关键词提取高亮"><a href="#关键词提取高亮" class="headerlink" title="关键词提取高亮"></a>关键词提取高亮</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">$content = <span class="string">'&lt;p&gt;周杰伦传世之作《晴天》&lt;/p&gt;:从前从前，&lt;div&gt;&lt;img class="img" src="htt://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike150%2C5%2C5%2C150%2C50/sign=3137f6103c4e251ff6faecaac6efa272/38dbb6fd5266d0167927ca029b2bd40735fa35d9.jpg"&gt;&lt;/div&gt;有个人&lt;strong&gt;爱你&lt;/strong&gt;很久，&lt;p&gt;风渐渐，把你吹得好远&lt;/p&gt;'</span>;</span><br><span class="line">echo $content;</span><br><span class="line">$tag = [</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'周杰伦'</span>,<span class="string">'url'</span>=&gt;<span class="string">'https://baike.baidu.com/item/%E5%91%A8%E6%9D%B0%E4%BC%A6/129156?fr=aladdin'</span>],</span><br><span class="line">    [<span class="string">'name'</span>=&gt;<span class="string">'晴天'</span>,<span class="string">'url'</span>=&gt;<span class="string">'https://baike.baidu.com/item/%E6%99%B4%E5%A4%A9/5429222'</span>],</span><br><span class="line">    ];</span><br><span class="line">preg_match_all(<span class="string">'/&lt;a[^&gt;]*&gt;.*?&lt;\/a&gt;|&lt;\/?[a-zA-Z]+[^&gt;]*&gt;|&lt;!--.*?--&gt;/'</span>, $content, $match);</span><br><span class="line">echo <span class="string">'&lt;pre&gt;'</span>;</span><br><span class="line">$html = $match[<span class="number">0</span>];</span><br><span class="line">$no_html = preg_split(<span class="string">'/&lt;a[^&gt;]*&gt;.*?&lt;\/a&gt;|&lt;\/?[a-zA-Z]+[^&gt;]*&gt;|&lt;!--.*?--&gt;/'</span>, $content);</span><br><span class="line"></span><br><span class="line">print_r($html);</span><br><span class="line"></span><br><span class="line">print_r($no_html);</span><br><span class="line">$tags  = [[],[],[]];</span><br><span class="line">foreach ($tag <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">    $tags[<span class="number">0</span>][] = <span class="string">'#'</span>.$v[<span class="string">'name'</span>].<span class="string">'#'</span>;</span><br><span class="line">    $tags[<span class="number">1</span>][] =  <span class="string">'#'</span>.md5($v[<span class="string">'name'</span>]). <span class="string">'#'</span>;</span><br><span class="line">    $tags[<span class="number">2</span>][] = <span class="string">"&lt;a href=&#123;$v['url']&#125;&gt;&#123;$v['name']&#125;&lt;/a&gt;"</span>;</span><br><span class="line">&#125;</span><br><span class="line">print_r($tags);</span><br><span class="line">foreach ($tags[<span class="number">0</span>] <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">    foreach ($no_html <span class="keyword">as</span> $key=&gt;$value)&#123;</span><br><span class="line">        <span class="keyword">if</span> (!trim($value)) <span class="keyword">continue</span>;</span><br><span class="line">        <span class="keyword">if</span>(preg_match($v,$value))&#123;</span><br><span class="line">            $no_html[$key] = preg_replace($v,$tags[<span class="number">1</span>][$k],$value,<span class="number">1</span>);</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;print_r($no_html);</span><br><span class="line">foreach ($no_html <span class="keyword">as</span> $key=&gt;$value)&#123;</span><br><span class="line">    <span class="keyword">if</span> (!trim($value)) <span class="keyword">continue</span>;</span><br><span class="line">    $no_html[$key] = str_replace($tags[<span class="number">1</span>],$tags[<span class="number">2</span>],$value);</span><br><span class="line">&#125;</span><br><span class="line">$res = [];</span><br><span class="line">$num = count($no_html);</span><br><span class="line">print_r($no_html);</span><br><span class="line"><span class="keyword">for</span> ($i=<span class="number">0</span>;$i&lt;$num;$i++)&#123;</span><br><span class="line">    $res[] = $no_html[$i];</span><br><span class="line">    <span class="keyword">if</span> (isset($html[$i]))&#123;</span><br><span class="line">        $res[]=$html[$i];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">echo implode(<span class="string">''</span>,$res);</span><br><span class="line">&lt;p&gt;&lt;a href=https://baike.baidu.com/item/%E5%91%A8%E6%9D%B0%E4%BC%A6/129156?fr=aladdin&gt;周杰伦&lt;/a&gt;传世之作《&lt;a href=https:<span class="comment">//baike.baidu.com/item/%E6%99%B4%E5%A4%A9/5429222&gt;晴天&lt;/a&gt;》&lt;/p&gt;:从前从前，&lt;div&gt;&lt;img class="img" src="htt://gss0.bdstatic.com/94o3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike150%2C5%2C5%2C150%2C50/sign=3137f6103c4e251ff6faecaac6efa272/38dbb6fd5266d0167927ca029b2bd40735fa35d9.jpg"&gt;&lt;/div&gt;有个人&lt;strong&gt;爱你&lt;/strong&gt;很久，&lt;p&gt;风渐渐，把你吹得好远&lt;/p&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 对字符串执行指定次数替换</span></span><br><span class="line"><span class="comment">     * @param  Mixed $search   查找目标值</span></span><br><span class="line"><span class="comment">     * @param  Mixed $replace  替换值</span></span><br><span class="line"><span class="comment">     * @param  Mixed $subject  执行替换的字符串／数组</span></span><br><span class="line"><span class="comment">     * @param  Int   $limit    允许替换的次数，默认为-1，不限次数</span></span><br><span class="line"><span class="comment">     * @return Mixed</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">str_replace_limit</span>(<span class="params">$search, $replace, $subject, $limit=<span class="number">-1</span></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(is_array($search))&#123;</span><br><span class="line">            foreach($search <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">                $search[$k] = <span class="string">'`'</span>. preg_quote($search[$k], <span class="string">'`'</span>). <span class="string">'`'</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            $search = <span class="string">'`'</span>. preg_quote($search, <span class="string">'`'</span>). <span class="string">'`'</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> preg_replace($search, $replace, $subject, $limit);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<h3 id="PHP-反射"><a href="#PHP-反射" class="headerlink" title="PHP 反射"></a>PHP 反射</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line">ReflectionClass</span><br><span class="line">ReflectionFunction</span><br><span class="line">ReflectionMethod</span><br><span class="line">ReflectionParameter</span><br><span class="line"><span class="class"><span class="keyword">class</span>  <span class="title">Printer</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span>  <span class="title">Student</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    private $name;</span><br><span class="line">    private $year;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$name, $year</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;name = $name;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;year = $year;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getValue</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">setBase</span>(<span class="params">Printer $printer, $name, $year = <span class="number">10</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;name = $name;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;year = $year;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$refl_class = <span class="keyword">new</span> ReflectionClass(Student::<span class="class"><span class="keyword">class</span>)</span>;</span><br><span class="line">$object = $refl_class-&gt;newInstanceArgs([<span class="string">"obama"</span>, <span class="number">100</span>]);</span><br><span class="line">echo get_class($object) . <span class="string">"\n"</span>;<span class="string">"Student"</span></span><br><span class="line">echo $object-&gt;getValue();obama</span><br><span class="line">$refl_method = $refl_class-&gt;getMethod(<span class="string">"setBase"</span>);</span><br><span class="line">echo get_class($refl_method) . <span class="string">"\n"</span>;</span><br><span class="line">$parameters = $refl_method-&gt;getParameters();</span><br><span class="line">foreach ($parameters <span class="keyword">as</span> $parameter) &#123;</span><br><span class="line">    echo $parameter-&gt;getName() . <span class="string">"\n"</span>;</span><br><span class="line">    <span class="keyword">if</span> ($parameter-&gt;getClass() != <span class="literal">null</span>) &#123;</span><br><span class="line">         echo $parameter-&gt;getClass()-&gt;getName() . <span class="string">"\n"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> ($parameter-&gt;isDefaultValueAvailable()) &#123;</span><br><span class="line">        echo $parameter-&gt;getDefaultValue() . <span class="string">"\n"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">printer</span><br><span class="line">Printer</span><br><span class="line">name</span><br><span class="line">year</span><br><span class="line"><span class="number">10</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/37162</span></span><br></pre></td></tr></table></figure>
<h3 id="经度和纬度计算距离两地距离"><a href="#经度和纬度计算距离两地距离" class="headerlink" title="经度和纬度计算距离两地距离"></a>经度和纬度计算距离两地距离</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">getDistance</span>(<span class="params">$lng1, $lat1, $lng2, $lat2</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">// 将角度转为狐度https://www.qqdeveloper.com/2019/09/26/longitude-and-langitude/</span></span><br><span class="line">    <span class="comment">//deg2rad()函数将角度转换为弧度</span></span><br><span class="line">    $radLat1 = deg2rad($lat1);</span><br><span class="line">    $radLat2 = deg2rad($lat2);</span><br><span class="line">    $radLng1 = deg2rad($lng1);</span><br><span class="line">    $radLng2 = deg2rad($lng2);</span><br><span class="line">    $a       = $radLat1 - $radLat2;</span><br><span class="line">    $b       = $radLng1 - $radLng2;</span><br><span class="line">    $s       = <span class="number">2</span> * asin(sqrt(pow(sin($a / <span class="number">2</span>), <span class="number">2</span>) + cos($radLat1) * cos($radLat2) * pow(sin($b / <span class="number">2</span>), <span class="number">2</span>))) * <span class="number">6378.137</span> * <span class="number">1000</span>;</span><br><span class="line">    <span class="keyword">return</span> $s;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="雪花算法"><a href="#雪花算法" class="headerlink" title="雪花算法"></a>雪花算法</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>bit:一般是符号位，不做处理</span><br><span class="line"><span class="number">41</span>bit:用来记录时间戳，这里可以记录 <span class="number">69</span> 年，如果设置好起始时间比如今年是 <span class="number">2018</span> 年，那么可以用到 <span class="number">2089</span> 年，到时候怎么办？要是这个系统能用 <span class="number">69</span> 年，我相信这个系统早都重构了好多次了。</span><br><span class="line"><span class="number">10</span>bit:<span class="number">10</span>bit 用来记录机器 ID，总共可以记录 <span class="number">1024</span> 台机器，一般用前 <span class="number">5</span> 位代表数据中心，后面 <span class="number">5</span> 位是某个数据中心的机器 ID</span><br><span class="line"><span class="number">12</span>bit:循环位，用来对同一个毫秒之内产生不同的 ID，<span class="number">12</span> 位可以最多记录 <span class="number">4095</span> 个，也就是在同一个机器同一毫秒最多记录 <span class="number">4095</span> 个，多余的需要进行等待下毫秒。上面只是一个将 <span class="number">64</span>bit 划分的标准，当然也不一定这么做，可以根据不同业务的具体场景来划分，比如下面给出一个业务场景：</span><br><span class="line"></span><br><span class="line">服务目前 QPS10 万，预计几年之内会发展到百万。</span><br><span class="line">当前机器三地部署，上海，北京，深圳都有。</span><br><span class="line">当前机器 <span class="number">10</span> 台左右，预计未来会增加至百台。</span><br><span class="line">适用场景:当我们需要无序不能被猜测的 ID，并且需要一定高性能，且需要 long 型，那么就可以使用我们雪花算法。比如常见的订单 ID，用雪花算法别人就无法猜测你每天的订单量是多少。</span><br><span class="line">PHP uniqid()函数可用于生成不重复的唯一标识符，该函数基于微秒级当前时间戳。在高并发或者间隔时长极短（如循环代码）的情况下，会出现大量重复数据。即使使用了第二个参数，也会重复，最好的方案是结合 md5 函数来生成唯一 ID。</span><br><span class="line">$units = array();</span><br><span class="line"><span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;<span class="number">1000000</span>;$i++)&#123;</span><br><span class="line">    $units[] = uniqid();</span><br><span class="line">&#125;</span><br><span class="line">$values  = array_count_values($units);</span><br><span class="line">$duplicates = [];</span><br><span class="line">foreach($values <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">    <span class="keyword">if</span>($v&gt;<span class="number">1</span>)&#123;</span><br><span class="line">        $duplicates[$k]=$v;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">echo <span class="string">'&lt;pre&gt;'</span>;</span><br><span class="line">print_r($duplicates);</span><br><span class="line">$units = array();</span><br><span class="line"><span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;<span class="number">1000000</span>;$i++)&#123;</span><br><span class="line">    $units[] = uniqid(<span class="string">''</span>,<span class="literal">true</span>);</span><br><span class="line">&#125;</span><br><span class="line">$values  = array_count_values($units);</span><br><span class="line">$duplicates = [];</span><br><span class="line">foreach($values <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">    <span class="keyword">if</span>($v&gt;<span class="number">1</span>)&#123;</span><br><span class="line">        $duplicates[$k]=$v;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">echo <span class="string">'&lt;pre&gt;'</span>;</span><br><span class="line">print_r($duplicates);</span><br><span class="line">$units = array();</span><br><span class="line"><span class="keyword">for</span>($i=<span class="number">0</span>;$i&lt;<span class="number">1000000</span>;$i++)&#123;</span><br><span class="line">    $units[]=md5(uniqid(md5(microtime(<span class="literal">true</span>)),<span class="literal">true</span>));</span><br><span class="line">&#125;</span><br><span class="line">$values  = array_count_values($units);</span><br><span class="line">$duplicates = [];</span><br><span class="line">foreach($values <span class="keyword">as</span> $k=&gt;$v)&#123;</span><br><span class="line">    <span class="keyword">if</span>($v&gt;<span class="number">1</span>)&#123;</span><br><span class="line">        $duplicates[$k]=$v;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">echo <span class="string">'&lt;pre&gt;'</span>;</span><br><span class="line">print_r($duplicates);</span><br><span class="line">使用 session_create_id()函数生成唯一标识符，经过实际测试发现，即使循环调用 session_create_id()一亿次，都没有出现过重复。</span><br><span class="line">php session_create_id()是 php <span class="number">7.1</span> 新增的函数，用来生成 session id，低版本无法使用。</span><br><span class="line">https:<span class="comment">//www.qqdeveloper.com/2019/09/12/snowflake/</span></span><br><span class="line">https:<span class="comment">//www.qqdeveloper.com/2019/09/16/php-unique-id/</span></span><br></pre></td></tr></table></figure>
<h3 id="跨域认证解决方案jwt"><a href="#跨域认证解决方案jwt" class="headerlink" title="跨域认证解决方案jwt"></a>跨域认证解决方案jwt</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">(图一)Session与Cookie认证与鉴权</span><br><span class="line"><span class="number">1.</span>客户端向服务端发送一个http请求。</span><br><span class="line"><span class="number">2.</span>服务端在收到客户端的请求时，生成一个唯一的 sessionid，这里需要将该生成的 session 存储在服务端,这个 sessionid 存储具体的 session 内容，默认的是文件存储，当然我们可以修改具体的存储方式，例如数据库存储。 <span class="number">3.</span>客户端在接受到这个 sessionid 时，存在 cookie 里面，每次请求时携带该 sessionid。 <span class="number">4.</span>服务端在接收到客户端的请求之后，根据客户端发送的 sessionid 来进行认证与授权。</span><br><span class="line">这里也推荐一下自己之前分享的一篇有关 session 于 cookie 的知识点。session 与 cookie 详解</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">(图二)传统的token授权</span><br><span class="line"><span class="number">1.</span>客户端向服务端发送一个http请求。</span><br><span class="line"><span class="number">2.</span>服务端在收到客户端的请求之后，生成一个唯一 token，这里需要将该生成的 token 存储在服务端，至于怎么存，可以和上面 session 与 cookie 的方式一致。也可以存在缓存数据库中，如 redis，memcached。 <span class="number">3.</span>服务端将该 token 返回给客户端，客户端存在本地，可以存请求头 header 中，也可以存在 cookie 中，同时也可以存在 localstorage 中。 <span class="number">4.</span>向服务端发送请求时，携带该 token，服务端进行认证或者授权。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">(图三)JWT认证模式</span><br><span class="line"><span class="number">1.</span>客户端向服务端发送一个http请求。</span><br><span class="line"><span class="number">2.</span>服务端根据 jwt 的生成规则，生成一个 token，并返回给客户端，这里服务端是不需要存储的。 <span class="number">3.</span>客户端在接受到该 token 时，存在客户端。 <span class="number">4.</span>客户端向服务端发送请求时，服务端对请求的 token 进行解析，如果发现解析出来的数据和生成的数据是一致的代表是一个合法的 token，则进行相应的操作。</span><br><span class="line">基于 session 都是需要服务端存储的，而 JWT 是不需要服务端来存储的。针对以上几点，总结如下：</span><br><span class="line">一、缺点 <span class="number">1.</span>容易遇到跨域问题。不同域名下是无法通过 session 直接来做到认证和鉴权的。 <span class="number">2.</span>分布式部署的系统，需要使用共享 session 机制 <span class="number">3.</span>容易出现 csrf 问题。</span><br><span class="line"></span><br><span class="line">二、优点 <span class="number">1.</span>方便灵活，服务器端直接创建一个 sessionid，下发给客户端，客户端请求携带 sessionid 即可。</span><br><span class="line"><span class="number">2.</span>session 存储在服务端，更加安全。 <span class="number">3.</span>便于服务端清除 session，让用户重新授权一次。</span><br><span class="line">JWT 是基于客户端存储的一种认证方式，然而 session 是基于服务端存储的一种认证方式。JWT 虽然不用服务端存储了，也可以避免跨域、csrf 等情况。但也存在如下几个不太好的地方。 <span class="number">1.</span>无法清除认证 token。由于 JWT 生成的 token 都是存储在客户端的，不能有服务端去主动清除，只有直到失效时间到了才能清除。除非服务端的逻辑做了改变。 <span class="number">2.</span>存储在客户端，相对服务端，安全性更低一些。当 JWT 生成的 token 被破解，我们不便于清除该 token。</span><br><span class="line">composer <span class="built_in">require</span> firebase/php-jwt</span><br><span class="line">private $key = <span class="string">'jwtKey'</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 生成JWT</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">createJwt</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $time  = time();</span><br><span class="line">        $key   = $<span class="keyword">this</span>-&gt;key;</span><br><span class="line">        $token = [</span><br><span class="line">            <span class="string">'iss'</span> =&gt; <span class="string">'https://www.qqdeveloper.com'</span>,<span class="comment">// 签发人</span></span><br><span class="line">            <span class="string">'exp'</span> =&gt; $time + <span class="number">86400</span>,<span class="comment">// 过期时间(这里的有效期时间为1天)</span></span><br><span class="line">            <span class="string">'sub'</span> =&gt; <span class="string">'主题内容'</span>,<span class="comment">// 主题</span></span><br><span class="line">            <span class="string">'aud'</span> =&gt; <span class="string">'受众内容'</span>,<span class="comment">// 受众</span></span><br><span class="line">            <span class="string">'nbf'</span> =&gt; $time,<span class="comment">// 生效时间</span></span><br><span class="line">            <span class="string">'iat'</span> =&gt; $time,<span class="comment">// 签发时间</span></span><br><span class="line">            <span class="string">'jti'</span> =&gt; <span class="number">123</span>,<span class="comment">// 编号</span></span><br><span class="line">            <span class="comment">// 额外自定义的数据</span></span><br><span class="line">            <span class="string">'data'</span> =&gt; [</span><br><span class="line">                <span class="string">'userName'</span> =&gt; <span class="string">'编程浪子走四方'</span></span><br><span class="line">            ]];</span><br><span class="line">        <span class="comment">// 调用生成加密方法('Payloadn内容','加密的键',['加密算法'],['加密的可以'],['JWT的header头'])</span></span><br><span class="line">        $jwt = JWT::encode($token, $key);</span><br><span class="line">        <span class="keyword">return</span> json([<span class="string">'data'</span> =&gt; $jwt]);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 解析JWT</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">analysisJwt</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            $key = $<span class="keyword">this</span>-&gt;key;</span><br><span class="line">            $jwt = <span class="string">'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9leGFtcGxlLm9yZyIsImV4cCI6MTU2ODA5NjE4MCwic3ViIjoiXHU0ZTNiXHU5ODk4XHU1MTg1XHU1YmI5IiwiYXVkIjoiXHU1M2Q3XHU0ZjE3XHU1MTg1XHU1YmI5IiwibmJmIjoxNTY4MDA5NzgwLCJpYXQiOjE1NjgwMDk3ODAsImp0aSI6MTIzLCJkYXRhIjp7InVzZXJOYW1lIjoiXHU3ZjE2XHU3YTBiXHU2ZDZhXHU1YjUwXHU4ZDcwXHU1NmRiXHU2NWI5In19.kHb_9Np0zjE25YE9czUEGvmFPYtqMJT9tuZzJTuMZl0'</span>;</span><br><span class="line">            <span class="comment">// 调用解密方法('JWT内容','解密的键,和加密时的加密键一直','加密算法')</span></span><br><span class="line">            $decoded = JWT::decode($jwt, $key, array(<span class="string">'HS256'</span>));</span><br><span class="line">            <span class="keyword">return</span> json([<span class="string">'message'</span> =&gt; $decoded]);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (\Exception $exception) &#123;</span><br><span class="line">            <span class="keyword">return</span> json([<span class="string">'message'</span> =&gt; $exception-&gt;getMessage()]);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//www.qqdeveloper.com/2019/09/09/Jwt/</span></span><br></pre></td></tr></table></figure>
<h3 id="加密算法"><a href="#加密算法" class="headerlink" title="加密算法"></a>加密算法</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line">MD5 结果是 <span class="number">128</span> 位摘要，SHa1 是 <span class="number">160</span> 位摘要。那么 MD5 的速度更快，而 SHA1 的强度更高。</span><br><span class="line"></span><br><span class="line">常用的对称加密算法有：AES 和 DES。</span><br><span class="line">DES：比较老的算法，一共有三个参数入口（原文，密钥，加密模式）。而 <span class="number">3</span>DES 只是 DES 的一种模式，是以 DES 为基础更安全的变形，对数据进行了三次加密，也是被指定为 AES 的过渡算法。</span><br><span class="line">AES:高级加密标准，新一代标准，加密速度更快，安全性更高（不用说优先选择）</span><br><span class="line">$content = <span class="string">"123456"</span>;</span><br><span class="line"><span class="comment">// 该函数是获取有哪些加密方式</span></span><br><span class="line">$encryptMethod = openssl_get_cipher_methods();</span><br><span class="line">$method1 = <span class="string">"AES-256-ECB"</span>;</span><br><span class="line">$key = <span class="string">"123"</span>;</span><br><span class="line"></span><br><span class="line">$encrypt2 = openssl_encrypt($content,$method1,$key);</span><br><span class="line">echo $encrypt2.<span class="string">"\n"</span>;</span><br><span class="line">$decrypt2 = openssl_decrypt($encrypt2,$method1,$key);</span><br><span class="line">echo $decrypt2.<span class="string">"\n"</span>;</span><br><span class="line"></span><br><span class="line">$method2 = <span class="string">"DES-EDE3-CFB"</span>;</span><br><span class="line">$encrypt3 = openssl_encrypt($content,$method2,$key);</span><br><span class="line">echo $encrypt3.<span class="string">"\n"</span>;</span><br><span class="line">$decrypt3 = openssl_decrypt($encrypt3,$method2,$key);</span><br><span class="line">echo $decrypt3.<span class="string">"\n"</span>;</span><br><span class="line">公开密钥（publickey:简称公钥）和私有密钥（privatekey:简称私钥）。公钥与私钥是一对，如果用公钥对数据进行加密，只有用对应的私钥才能解密。因为加密和解密使用的是两个不同的密钥，所以这种算法叫作非对称加密算法。</span><br><span class="line">非对称密码体制的特点：算法强度复杂、安全性依赖于算法与密钥但是由于其算法复杂，而使得加密解密速度没有对称加密解密的速度快。对称密码体制中只有一种密钥，并且是非公开的，如果要解密就得让对方知道密钥。所以保证其安全性就是保证密钥的安全，而非对称密钥体制有两种密钥，其中一个是公开的，这样就可以不需要像对称密码那样传输对方的密钥了。这样安全性就大了很多。</span><br><span class="line"><span class="number">1.</span>A 要向 B 发送信息，A 和 B 都要产生一对用于加密的公钥和私钥。</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span>A 的私钥保密，A 的公钥告诉 B；B 的私钥保密，B 的公钥告诉 A。</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span>A 要给 B 发送信息时，A 用 B 的公钥加密信息，因为 A 知道 B 的公钥。</span><br><span class="line"></span><br><span class="line"><span class="number">4.</span>A 将这个消息发给 B（已经用 B 的公钥加密消息）。</span><br><span class="line"></span><br><span class="line"><span class="number">5.</span>B 收到这个消息后，B 用自己的私钥解密 A 的消息。其他所有收到这个报文的人都无法解密，因为只有 B 才有 B 的私钥。</span><br><span class="line"><span class="comment">// 公钥内容</span></span><br><span class="line">$publicKey = <span class="string">"-----BEGIN PUBLIC KEY-----</span></span><br><span class="line"><span class="string">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA448HrtB/ORfECv/owcAB</span></span><br><span class="line"><span class="string">fN/PfAy2G7BGPkIy96QuFQhgf7pTF+X4x4wRZgRtdmhnMgtpessx6UXaNzRaDsa8</span></span><br><span class="line"><span class="string">IWozFTrNu3P7xcJxdcWbdlHdMYASmp4xOe6ct/tGURI8HBn4yjxTES4IFAoPxNCt</span></span><br><span class="line"><span class="string">dgs31dsJnq0uUa3C1VTWbPtdZX+GX/GOsl2hbJOhn/WrRlOIGzI2oSjhdaPXGD1w</span></span><br><span class="line"><span class="string">xXKCZM1RhcjQoWQLnFerlOeqNRhW+qgoJ7nRD+PhEajA0LhUMHvyeFR+A37DuFdI</span></span><br><span class="line"><span class="string">KBD58b2EnBZmYyZL7umeNjjhruSyeD1Y5qOvuKOoL7vQOVzAdVwokcMqDmXurR4s</span></span><br><span class="line"><span class="string">kQIDAQAB</span></span><br><span class="line"><span class="string">-----END PUBLIC KEY-----</span></span><br><span class="line"><span class="string">"</span>;</span><br><span class="line"><span class="comment">// 私钥内容</span></span><br><span class="line">$privateKey = <span class="string">"-----BEGIN PRIVATE KEY-----</span></span><br><span class="line"><span class="string">MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDjjweu0H85F8QK</span></span><br><span class="line"><span class="string">/+jBwAF83898DLYbsEY+QjL3pC4VCGB/ulMX5fjHjBFmBG12aGcyC2l6yzHpRdo3</span></span><br><span class="line"><span class="string">NFoOxrwhajMVOs27c/vFwnF1xZt2Ud0xgBKanjE57py3+0ZREjwcGfjKPFMRLggU</span></span><br><span class="line"><span class="string">Cg/E0K12CzfV2wmerS5RrcLVVNZs+11lf4Zf8Y6yXaFsk6Gf9atGU4gbMjahKOF1</span></span><br><span class="line"><span class="string">o9cYPXDFcoJkzVGFyNChZAucV6uU56o1GFb6qCgnudEP4+ERqMDQuFQwe/J4VH4D</span></span><br><span class="line"><span class="string">fsO4V0goEPnxvYScFmZjJkvu6Z42OOGu5LJ4PVjmo6+4o6gvu9A5XMB1XCiRwyoO</span></span><br><span class="line"><span class="string">Ze6tHiyRAgMBAAECggEBALtXC1ouKC8Wk70ChdrMee0WTLixtlMBQjMLSO57abzD</span></span><br><span class="line"><span class="string">Er7U5IeuOqv9cm1sg7mRpjObFZGUK1kCuu3r2aCEmGliBwAZUzpZ+BMNS19L+frk</span></span><br><span class="line"><span class="string">1pdj+uz0A07QVJFa+r7PplD0SNAl7bUdEmV9CxJbQhMGlUcodrj9lj6EMPx0Rbud</span></span><br><span class="line"><span class="string">gBLJbZCK+h8lNgbGYce+J0+CDDnTapsPKFP/DvwZwgE4CkpVciEtbH2RzU45qRVI</span></span><br><span class="line"><span class="string">If7/3YBB3q+eD4GrIuBgmLUT7bs2vKn/RXxN8YARoEwUqj/Gg2iXQeSPtW0iWuV/</span></span><br><span class="line"><span class="string">cbCT6Sfb1J7KGXiEDKrsNH+e29TcXsIDbrMHSyj3IeECgYEA8gtQJbHDhcXjDSx1</span></span><br><span class="line"><span class="string">5SWKpWdhFNEp/ggdFj8hAroVBHPmGelvkY6i4OZ/IGulzIrJY2uxXwU91KMuoZ5/</span></span><br><span class="line"><span class="string">IdOQSZiehsba1PCn9ZAVY/KZZvfAYX96tUKUmnar1GyhhcSAljPK2zKqYbGnJbnI</span></span><br><span class="line"><span class="string">TVMpSthdNgEi/XNrEWrpXFWimI0CgYEA8K3nhWBt4xG87x9ifEpJjFlf/8hlmKr9</span></span><br><span class="line"><span class="string">8SMi4qm/ja3huL4si1VVkO8flqqhkkr+HqtBKOe+bYMZBUDtYnv/netMeQuCdvJY</span></span><br><span class="line"><span class="string">sfXPeSguXgGhjxP6gNswMYnzOykoGyPT84gOXBuY2M8X9nB6SkAQ+OL/sf0ltQdP</span></span><br><span class="line"><span class="string">4mdQNQBKjRUCgYEA5sLmbKmoMZfSurKSzB8Yqk1/fytTj8AIizcwr7rdYttkm3u1</span></span><br><span class="line"><span class="string">RN7qZuUaerxm3DXNfx4jguYqZtoVET1dE9DylVgOe4yHAdFXMIVn/1xB6Kt4HPw+</span></span><br><span class="line"><span class="string">7yVFLGbLt8DB1hjcR1elpYoOawnGw+72CtKoYZUaeOxogZ9Sis6VIdT7KdkCgYEA</span></span><br><span class="line"><span class="string">tkmw0fcwI0xbAe2OZT7Kp89Fg3BfapsPzORk1rHkkEVDce4vxLQ0I5rJHQ9NYoUE</span></span><br><span class="line"><span class="string">JWxl5LppI36oo68CXJY4C36cpA1QmhCBlv/rTQNe4vpvR/PExnW88bhfDc7lPnEL</span></span><br><span class="line"><span class="string">ZicFYUPRp1xq9M9KABS4Bhm/uipWtd685WiEejAnRuUCgYA4ddYkl6XwA/HQ1Kyr</span></span><br><span class="line"><span class="string">iwAllDdusuGW62DMeXC2h2qw8yCvG38YAQu8lRDCFm0JW/sD2sgVCtt9c147ZFoB</span></span><br><span class="line"><span class="string">mUghpFOZRZvbxEdPzIyb4Gn0wN+3Jwjrl9uPiY82q92G0E253PKug2EJYapa411/</span></span><br><span class="line"><span class="string">fxrEXMi/X+VwggoEnOqXsbyrHA==</span></span><br><span class="line"><span class="string">-----END PRIVATE KEY-----</span></span><br><span class="line"><span class="string">"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 加密字符串</span></span><br><span class="line">$content = <span class="string">"123456"</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 使用公钥加密，私钥解密</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">$encrypt = <span class="string">""</span>;</span><br><span class="line">openssl_public_encrypt($content,$encrypt,$publicKey);</span><br><span class="line">echo <span class="string">"加密之后的数据为:\n"</span>;</span><br><span class="line">var_dump($encrypt);</span><br><span class="line"></span><br><span class="line">$decrypt = <span class="string">""</span>;</span><br><span class="line">openssl_private_decrypt($encrypt,$decrypt,$privateKey);</span><br><span class="line">echo <span class="string">"解密之后的数据为:\n"</span>;</span><br><span class="line">var_dump($decrypt);</span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 使用私钥加密，公钥解密</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">$encrypt1 = <span class="string">""</span>;</span><br><span class="line">openssl_private_encrypt($content,$encrypt1,$privateKey);</span><br><span class="line">echo <span class="string">"加密之后的数据为:\n"</span>;</span><br><span class="line">var_dump($encrypt1);</span><br><span class="line">$decrypt1 = <span class="string">""</span>;</span><br><span class="line">openssl_public_decrypt($encrypt1,$decrypt1,$publicKey);</span><br><span class="line">echo <span class="string">"解密之后的数据为:\n"</span>;</span><br><span class="line">var_dump($decrypt1);</span><br><span class="line">https:<span class="comment">//www.qqdeveloper.com/2019/08/28/data-encrypt/</span></span><br></pre></td></tr></table></figure>
<h3 id="常用排序算法之桶排序"><a href="#常用排序算法之桶排序" class="headerlink" title="常用排序算法之桶排序"></a>常用排序算法之桶排序</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">桶排序其实就是一种归纳排序，他将要进行排序的数组分到有限的桶里面，然后对桶进行归纳排序，可以理解成他是一个归纳结果。</span><br><span class="line">小哼的班上只有 <span class="number">5</span> 个同学，这 <span class="number">5</span> 个同学分别考了 <span class="number">5</span> 分、<span class="number">3</span> 分、 <span class="number">5</span> 分、<span class="number">2</span> 分和 <span class="number">8</span> 分，哎考得真是惨不忍睹（满分是 <span class="number">10</span></span><br><span class="line">分）。接下来将分数进行从小到大排序， 排序后是 <span class="number">2</span> <span class="number">3</span> <span class="number">5</span> <span class="number">5</span> <span class="number">8</span>。</span><br><span class="line"></span><br><span class="line">思路分析</span><br><span class="line">  首先，他的总分是 <span class="number">10</span> 分，也就是说有 <span class="number">11</span> 种情况，所以我们需要 <span class="number">11</span> 个桶，开始的时候我们都不给这些桶加水，也就是每个桶是 <span class="number">0</span>，每个桶都标号从 <span class="number">0</span> 开始到 <span class="number">10</span> 结束。</span><br><span class="line"></span><br><span class="line">  然后呢我们可以看到有 <span class="number">5</span> 个同学，所以，我们可以通过循环拿到这五个同学的分数，拿到分数后，比如我先拿到的是 <span class="number">8</span> 分，那么我们就给标号为 <span class="number">8</span> 的桶加 <span class="number">1</span> 刻度水（当然也不一定是刻度为单位，也可以是升，毫升什么的，这里是方便理解），这样下来，标号为 <span class="number">2</span> 的桶里有 <span class="number">1</span> 刻度水，标号为 <span class="number">3</span> 的桶里有 <span class="number">1</span> 刻度水，标号为 <span class="number">5</span> 的桶里有 <span class="number">2</span> 刻度水，标号为 <span class="number">8</span> 的桶里有 <span class="number">1</span> 刻度水。</span><br><span class="line"></span><br><span class="line">  最后，我们对这些桶里面的水进行统计，从前往后，有一刻度水的就打印这个桶编号 <span class="number">1</span> 次，两刻度水的就打印桶编号 <span class="number">2</span> 次</span><br><span class="line"> public <span class="function"><span class="keyword">function</span> <span class="title">index</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">//需要进行排序的数组</span></span><br><span class="line">        $arr = array(<span class="number">5</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">2</span>, <span class="number">8</span>);</span><br><span class="line">        <span class="comment">//声明一个空数组</span></span><br><span class="line">        $list = array();</span><br><span class="line">        <span class="comment">//将空数组赋值0</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt;= <span class="number">10</span>; $i++) &#123;</span><br><span class="line">            $list[$i] = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//按照相应的进行重新赋值</span></span><br><span class="line">        <span class="keyword">for</span> ($j = <span class="number">0</span>; $j &lt; sizeof($arr); $j++) &#123;</span><br><span class="line">            $list[$arr[$j]]++;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//打印排序后的结果</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">1</span>; $i &lt;= <span class="number">10</span>; $i++) &#123;</span><br><span class="line">            <span class="keyword">for</span> ($j = <span class="number">1</span>; $j &lt;= $list[$i]; $j++) &#123;</span><br><span class="line">                var_dump($i);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/37185</span></span><br><span class="line">$data = [<span class="number">5</span>,<span class="number">3</span>,<span class="number">5</span>,<span class="number">2</span>,<span class="number">8</span>];</span><br><span class="line">$count = array_count_values($data);</span><br><span class="line">$res = [];</span><br><span class="line"><span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">11</span>; $i++) &#123;</span><br><span class="line">    <span class="keyword">if</span> (isset($count[$i])) &#123;</span><br><span class="line">        <span class="keyword">for</span> ($j = <span class="number">0</span>; $j &lt; $count[$i]; $j++) &#123;</span><br><span class="line">            $res[] = $i;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="PHP-爬虫爬取社区文章"><a href="#PHP-爬虫爬取社区文章" class="headerlink" title="PHP 爬虫爬取社区文章"></a>PHP 爬虫爬取社区文章</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line">Goutte composer <span class="built_in">require</span> fabpot/goutte</span><br><span class="line">Guzzle composer <span class="built_in">require</span> guzzlehttp/guzzle:~<span class="number">6.0</span></span><br><span class="line">php artisan make:command Spider</span><br><span class="line">namespace App\Console\Commands;</span><br><span class="line"></span><br><span class="line">use Goutte\Client <span class="keyword">as</span> GoutteClient;</span><br><span class="line">use GuzzleHttp\Client <span class="keyword">as</span> GuzzleClient;</span><br><span class="line">use GuzzleHttp\Pool;</span><br><span class="line">use Illuminate\Console\Command;</span><br><span class="line">use Illuminate\Support\Facades\Storage;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Spider</span> <span class="keyword">extends</span> <span class="title">Command</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line"></span><br><span class="line">    protected $signature = <span class="string">'command:spider &#123;concurrency&#125; &#123;keyWords*&#125;'</span>; <span class="comment">//concurrency为并发数  keyWords为查询关键词</span></span><br><span class="line"></span><br><span class="line">    protected $description = <span class="string">'php spider'</span>;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        parent::__construct();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">handle</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">//</span></span><br><span class="line">        $concurrency = $<span class="keyword">this</span>-&gt;argument(<span class="string">'concurrency'</span>);  <span class="comment">//并发数</span></span><br><span class="line">        $keyWords = $<span class="keyword">this</span>-&gt;argument(<span class="string">'keyWords'</span>);    <span class="comment">//查询关键词</span></span><br><span class="line">        $guzzleClent = <span class="keyword">new</span> GuzzleClient();</span><br><span class="line">        $client = <span class="keyword">new</span> GoutteClient();</span><br><span class="line">        $client-&gt;setClient($guzzleClent);</span><br><span class="line">        $request = <span class="function"><span class="keyword">function</span> (<span class="params">$total</span>) <span class="title">use</span> (<span class="params">$client,$keyWords</span>)</span>&#123;</span><br><span class="line">            foreach ($keyWords <span class="keyword">as</span> $key)&#123;</span><br><span class="line">                $url=<span class="string">'https://laravel-china.org/search?q='</span>.$key;</span><br><span class="line">                <span class="keyword">yield</span> <span class="function"><span class="keyword">function</span> (<span class="params"></span>) <span class="title">use</span>(<span class="params">$client,$url</span>)</span>&#123;</span><br><span class="line">                    <span class="keyword">return</span> $client-&gt;request(<span class="string">'GET'</span>,$url);</span><br><span class="line">                &#125;;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;;</span><br><span class="line">        $pool = <span class="keyword">new</span> Pool($guzzleClent,$request(count($keyWords)),[</span><br><span class="line">            <span class="string">'concurrency'</span> =&gt; $concurrency,</span><br><span class="line">            <span class="string">'fulfilled'</span> =&gt; <span class="function"><span class="keyword">function</span> (<span class="params">$response, $index</span>) <span class="title">use</span> (<span class="params">$client</span>)</span>&#123;</span><br><span class="line">                $response-&gt;filter(<span class="string">'h2 &gt; a'</span>)-&gt;reduce(<span class="function"><span class="keyword">function</span>(<span class="params">$node</span>) <span class="title">use</span> (<span class="params">$client</span>)</span>&#123;</span><br><span class="line">                    <span class="keyword">if</span>(strlen($node-&gt;attr(<span class="string">'title'</span>))==<span class="number">0</span>) &#123;</span><br><span class="line">                        $title = $node-&gt;text();             <span class="comment">//文章标题</span></span><br><span class="line">                        $link = $node-&gt;attr(<span class="string">'href'</span>);        <span class="comment">//文章链接</span></span><br><span class="line">                        $carwler = $client-&gt;request(<span class="string">'GET'</span>,$link);       <span class="comment">//进入文章</span></span><br><span class="line">                        $content=$carwler-&gt;filter(<span class="string">'#emojify'</span>)-&gt;first()-&gt;text();     <span class="comment">//获取内容</span></span><br><span class="line">                        Storage::disk(<span class="string">'local'</span>)-&gt;put($title,$content);           <span class="comment">//储存在本地</span></span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;);</span><br><span class="line">            &#125;,</span><br><span class="line">            <span class="string">'rejected'</span> =&gt; <span class="function"><span class="keyword">function</span> (<span class="params">$reason, $index</span>)</span>&#123;</span><br><span class="line">                $<span class="keyword">this</span>-&gt;error(<span class="string">"Error is "</span>.$reason);</span><br><span class="line">            &#125;</span><br><span class="line">        ]);</span><br><span class="line">        <span class="comment">//开始爬取</span></span><br><span class="line">        $promise = $pool-&gt;promise();</span><br><span class="line">        $promise-&gt;wait();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;https:<span class="comment">//learnku.com/articles/6272/php-crawler-crawls-community-article-content</span></span><br></pre></td></tr></table></figure>
<h3 id="guzzle使用cookies实现模拟登录"><a href="#guzzle使用cookies实现模拟登录" class="headerlink" title="guzzle使用cookies实现模拟登录"></a>guzzle使用cookies实现模拟登录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br></pre></td><td class="code"><pre><span class="line">$client = <span class="keyword">new</span> \GuzzleHttp\Client([<span class="string">'cookies'</span> =&gt; <span class="literal">true</span>]);</span><br><span class="line">$r = $client-&gt;request(<span class="string">'GET'</span>, <span class="string">'http://httpbin.org/cookies'</span>);</span><br><span class="line">namespace App\Http\Controllers;</span><br><span class="line">use GuzzleHttp\Client;</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">TestController</span> <span class="keyword">extends</span> <span class="title">Controller</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">    $client = <span class="keyword">new</span> Client([<span class="string">'cookies'</span> =&gt; <span class="literal">true</span>]);</span><br><span class="line">        <span class="comment">// 登录账号https://phpartisan.cn/news/47.html</span></span><br><span class="line">        $login = $client-&gt;request(<span class="string">'POST'</span>,<span class="string">'登录地址'</span>,[<span class="string">'form_params'</span> =&gt; [<span class="string">'usename'</span> =&gt; <span class="string">'账号'</span>,<span class="string">'password'</span>=&gt;<span class="string">'密码'</span>,<span class="string">'remember'</span>=&gt;<span class="string">'false'</span>]]);</span><br><span class="line">        <span class="comment">// 请求需要登录才能访问的页面</span></span><br><span class="line">        $response = $client-&gt;request(<span class="string">'GET'</span>,<span class="string">""</span>);</span><br><span class="line">        $data = $response-&gt;getBody();</span><br><span class="line">        echo $data;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">$response = $client-&gt;request(<span class="string">'POST'</span>, <span class="string">'http://httpbin.org/post'</span>, [</span><br><span class="line">    <span class="string">'multipart'</span> =&gt; [</span><br><span class="line">        [</span><br><span class="line">            <span class="string">'name'</span>     =&gt; <span class="string">'field_name'</span>,</span><br><span class="line">            <span class="string">'contents'</span> =&gt; <span class="string">'abc'</span></span><br><span class="line">        ],</span><br><span class="line">        [</span><br><span class="line">            <span class="string">'name'</span>     =&gt; <span class="string">'file_name'</span>,</span><br><span class="line">            <span class="string">'contents'</span> =&gt; fopen(<span class="string">'/path/to/file'</span>, <span class="string">'r'</span>)</span><br><span class="line">        ],</span><br><span class="line">        [</span><br><span class="line">            <span class="string">'name'</span>     =&gt; <span class="string">'other_file'</span>,</span><br><span class="line">            <span class="string">'contents'</span> =&gt; <span class="string">'hello'</span>,</span><br><span class="line">            <span class="string">'filename'</span> =&gt; <span class="string">'filename.txt'</span>,</span><br><span class="line">            <span class="string">'headers'</span>  =&gt; [</span><br><span class="line">                <span class="string">'X-Foo'</span> =&gt; <span class="string">'this is an extra header to include'</span></span><br><span class="line">            ]</span><br><span class="line">        ]</span><br><span class="line">    ]</span><br><span class="line">]);</span><br><span class="line">$response = $client-&gt;request(<span class="string">'POST'</span>, <span class="string">'http://httpbin.org/post'</span>, [</span><br><span class="line">    <span class="string">'form_params'</span> =&gt; [</span><br><span class="line">        <span class="string">'field_name'</span> =&gt; <span class="string">'abc'</span>,</span><br><span class="line">        <span class="string">'other_field'</span> =&gt; <span class="string">'123'</span>,</span><br><span class="line">        <span class="string">'nested_field'</span> =&gt; [</span><br><span class="line">            <span class="string">'nested'</span> =&gt; <span class="string">'hello'</span></span><br><span class="line">        ]</span><br><span class="line">    ]</span><br><span class="line">]);</span><br><span class="line">$response = $client-&gt;request(<span class="string">'POST'</span>, <span class="string">'https://credit.baiqishi.com/clweb/api/common/gettoken'</span>, [<span class="string">'json'</span> =&gt; [<span class="string">'token'</span>=&gt;<span class="string">''</span>]]);</span><br><span class="line">发送并发请求</span><br><span class="line">Guzzle你可以使用<span class="built_in">Promise</span>和异步请求来同时发送多个请求：</span><br><span class="line"></span><br><span class="line">$client = <span class="keyword">new</span> Client();</span><br><span class="line"><span class="comment">// 创建一个请求列表</span></span><br><span class="line">$promises = [</span><br><span class="line">    <span class="string">'baidu'</span> =&gt; $client-&gt;getAsync(<span class="string">'https://www.baidu.com/'</span>),</span><br><span class="line">    <span class="string">'jd'</span>   =&gt; $client-&gt;getAsync(<span class="string">'http://www.jd.com/'</span>),</span><br><span class="line">    <span class="string">'earnp'</span>  =&gt; $client-&gt;getAsync(<span class="string">'http://bbs.earnp.com/'</span>),</span><br><span class="line">];</span><br><span class="line"><span class="comment">// 等待所有请求完成</span></span><br><span class="line">$results = <span class="built_in">Promise</span>\unwrap($promises);</span><br><span class="line"><span class="comment">// 查看请求结果</span></span><br><span class="line">$baidu = $results[<span class="string">'baidu'</span>]-&gt;getHeader(<span class="string">'Content-Length'</span>);</span><br><span class="line">$jd = $results[<span class="string">'jd'</span>]-&gt;getHeader(<span class="string">'Content-Length'</span>);</span><br><span class="line">$earnp = $results[<span class="string">'earnp'</span>]-&gt;getHeader(<span class="string">'Content-Length'</span>);</span><br><span class="line">dd($jd);</span><br><span class="line">上面确定了并发的数量，当你想发送不确定数量的请求时，可以使用GuzzleHttp\Pool对象：</span><br><span class="line"></span><br><span class="line">$client = <span class="keyword">new</span> Client();</span><br><span class="line">$requests = <span class="function"><span class="keyword">function</span> (<span class="params">$total</span>) </span>&#123;</span><br><span class="line">    $uri = <span class="string">'http://baidu.com'</span>;</span><br><span class="line">    <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $total; $i++) &#123;</span><br><span class="line">        <span class="keyword">yield</span> <span class="keyword">new</span> Request(<span class="string">'GET'</span>, $uri);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line">$pool = <span class="keyword">new</span> Pool($client, $requests(<span class="number">100</span>), [</span><br><span class="line">    <span class="string">'concurrency'</span> =&gt; <span class="number">5</span>,</span><br><span class="line">    <span class="string">'fulfilled'</span> =&gt; <span class="function"><span class="keyword">function</span> (<span class="params">$response, $index</span>) </span>&#123;</span><br><span class="line">        <span class="comment">// 成功的响应。</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="string">'rejected'</span> =&gt; <span class="function"><span class="keyword">function</span> (<span class="params">$reason, $index</span>) </span>&#123;</span><br><span class="line">        <span class="comment">// 失败的响应</span></span><br><span class="line">    &#125;,</span><br><span class="line">]);</span><br><span class="line"><span class="comment">// 构建请求https://phpartisan.cn/news/44.html</span></span><br><span class="line">$promise = $pool-&gt;promise();</span><br><span class="line"><span class="comment">// 等待请求池完成。</span></span><br><span class="line">$promise-&gt;wait();</span><br></pre></td></tr></table></figure>
<h3 id="3DES加密"><a href="#3DES加密" class="headerlink" title="3DES加密"></a>3DES加密</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">php7<span class="number">.1</span>开始不再支持mcrypt_encrypt，所有这里会有<span class="number">2</span>个版本的<span class="number">3</span>DES加密并且对接JAVA,具体实施如下：</span><br><span class="line"></span><br><span class="line">php版本小于php7<span class="number">.0</span></span><br><span class="line"></span><br><span class="line">使用mcrypt方法即可进行加密解密。</span><br><span class="line"></span><br><span class="line">$size = mcrypt_get_block_size(<span class="string">'des'</span>, <span class="string">'ecb'</span>);</span><br><span class="line">$td = mcrypt_module_open(MCRYPT_3DES, <span class="string">''</span>, <span class="string">'ecb'</span>, <span class="string">''</span>);</span><br><span class="line">$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);</span><br><span class="line"><span class="comment">// 使用MCRYPT_3DES算法,cbc模式</span></span><br><span class="line">@mcrypt_generic_init($td, $key, $iv);</span><br><span class="line"><span class="comment">// 初始处理</span></span><br><span class="line">$data = mcrypt_generic($td, $input);<span class="comment">// 加密</span></span><br><span class="line">var_dump($data);</span><br><span class="line">$decrypted = mdecrypt_generic($td, $data); <span class="comment">// 解密</span></span><br><span class="line">var_dump($decrypted);</span><br><span class="line">mcrypt_generic_deinit($td);</span><br><span class="line"><span class="comment">// 结束</span></span><br><span class="line">mcrypt_module_close($td);</span><br><span class="line">php版本大于php7<span class="number">.0</span></span><br><span class="line"></span><br><span class="line">大于<span class="number">7.0</span>版本我们开始使用openssl进行加密解密处理了：</span><br><span class="line"></span><br><span class="line"># 加密</span><br><span class="line">$data = openssl_encrypt($input,<span class="string">'des-ede3'</span>,$key,<span class="number">0</span>);</span><br><span class="line">openssl_encrypt加密会按照加密模式进行加密，之后还会进行base64加密，所以需要进行解密</span><br><span class="line"></span><br><span class="line">base64_decode($data);</span><br><span class="line">所以解密方法如下：</span><br><span class="line"></span><br><span class="line"># 解密https://phpartisan.cn/news/122.html</span><br><span class="line">$decrypted = openssl_decrypt(base64_decode($data),<span class="string">'des-ede3'</span>,$key,OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING);</span><br></pre></td></tr></table></figure>
<h3 id="API-系列-深入浅出-JSON-Web-Token-jwt"><a href="#API-系列-深入浅出-JSON-Web-Token-jwt" class="headerlink" title="API 系列 - 深入浅出 JSON Web Token jwt"></a>API 系列 - 深入浅出 JSON Web Token jwt</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">JWT 的认证过程如下：</span><br><span class="line"></span><br><span class="line">客户端发送登录信息（用户 ID，密码）</span><br><span class="line">服务端基于密钥生成 JWT，返回给客户端</span><br><span class="line">客户端在接下来的请求中将 Token 放在头部中一起发送给服务端</span><br><span class="line">服务端对 JWT 进行验证</span><br><span class="line">JWT 可分为三部分，用 . 符号隔开</span><br><span class="line"></span><br><span class="line">Header 头部</span><br><span class="line">Payload 负载</span><br><span class="line">Signature 签名</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">base64url</span>(<span class="params">string $string</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">  <span class="keyword">return</span> str_replace(<span class="string">'='</span>, <span class="string">''</span>, strtr(base64_encode($string), <span class="string">'+/'</span>, <span class="string">'-_'</span>));</span><br><span class="line">&#125;</span><br><span class="line">$header = [</span><br><span class="line">  <span class="string">'alg'</span> =&gt; <span class="string">'HS256'</span>,</span><br><span class="line">  <span class="string">'typ'</span> =&gt; <span class="string">'JWT'</span>,</span><br><span class="line">];</span><br><span class="line">$payload = [</span><br><span class="line">  <span class="string">'sub'</span>   =&gt; <span class="number">1</span>,</span><br><span class="line">  <span class="string">'name'</span>  =&gt; <span class="string">'Mind Geek'</span>,</span><br><span class="line">  <span class="string">'admin'</span> =&gt; <span class="literal">true</span>,</span><br><span class="line">];</span><br><span class="line">$secret = <span class="string">'mind-geek-jwt'</span>;</span><br><span class="line"><span class="comment">// Header</span></span><br><span class="line">$base64Header = base64url(json_encode($header));</span><br><span class="line"></span><br><span class="line"><span class="comment">// Payload</span></span><br><span class="line">$base64Payload = base64url(json_encode($payload));</span><br><span class="line">$encryp = $base64Header.<span class="string">"."</span>.$base64Payload;</span><br><span class="line">$signature = hash_hmac(<span class="string">'sha256'</span>, $encryp, $secret, <span class="literal">true</span>);</span><br><span class="line">$base64Signature = base64url($signature);</span><br><span class="line">$token = $base64Header.<span class="string">"."</span>.$base64Payload.<span class="string">"."</span>.$base64Signature;</span><br><span class="line">$token = <span class="string">'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJNaW5kIEdlZWsiLCJhZG1pbiI6dHJ1ZX0.0_dneYOin4yWRYlD-KmfvGEY6AhjA_zDyyvPhgYq2sU'</span>;</span><br><span class="line">list($base64Header, $base64Payload, $base64Signature) = explode(<span class="string">'.'</span>, $token);</span><br><span class="line">$encryp = $base64Header.<span class="string">"."</span>.$base64Payload;</span><br><span class="line">$signature = hash_hmac(<span class="string">'sha256'</span>, $encryp, $secret, <span class="literal">true</span>);</span><br><span class="line">$computedBase64Signature = base64url($signature);</span><br><span class="line"><span class="keyword">if</span>($computedBase64Signature === $base64Signature)&#123;</span><br><span class="line">    echo <span class="string">"认证成功!"</span>;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/37426</span></span><br></pre></td></tr></table></figure>
<h3 id="UTC-格式的时间转换"><a href="#UTC-格式的时间转换" class="headerlink" title="UTC 格式的时间转换"></a>UTC 格式的时间转换</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">use Carbon\Carbon;</span><br><span class="line"></span><br><span class="line">$input = <span class="number">2018</span><span class="number">-01</span><span class="number">-01</span>T12:<span class="number">00</span>:<span class="number">00.000</span>+<span class="number">0100</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 实例化一个 Carbon 对象</span></span><br><span class="line">$carbon = Carbon::make($input);</span><br><span class="line"><span class="comment">// 转换时区</span></span><br><span class="line">$carbon-&gt;setTimezone(<span class="string">'PRC'</span>);</span><br><span class="line"><span class="comment">// 输出查看</span></span><br><span class="line">echo $carbon-&gt;toDateTimeString();</span><br></pre></td></tr></table></figure>
<h3 id="Curl-下载文件实时进度条显示"><a href="#Curl-下载文件实时进度条显示" class="headerlink" title="Curl 下载文件实时进度条显示"></a>Curl 下载文件实时进度条显示</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Request</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    protected $bar;</span><br><span class="line">    <span class="comment">// 是否下载完成</span></span><br><span class="line">    protected $downloaded = <span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">// 初始化一个进度条https://github.com/dariuszp/cli-progress-bar</span></span><br><span class="line">        $<span class="keyword">this</span>-&gt;bar = <span class="keyword">new</span> CliProgressBar(<span class="number">100</span>);</span><br><span class="line">        $<span class="keyword">this</span>-&gt;bar-&gt;display();</span><br><span class="line">        $<span class="keyword">this</span>-&gt;bar-&gt;setColorToRed();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">download</span>(<span class="params">$url</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $ch = curl_init();</span><br><span class="line"></span><br><span class="line">        curl_setopt($ch, CURLOPT_URL, $url);</span><br><span class="line">        curl_setopt($ch, CURLOPT_RETURNTRANSFER, <span class="number">1</span>);</span><br><span class="line">        <span class="comment">// 开启进度条</span></span><br><span class="line">        curl_setopt($ch, CURLOPT_NOPROGRESS, <span class="number">0</span>);</span><br><span class="line">        <span class="comment">// 进度条的触发函数</span></span><br><span class="line">        curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, [$<span class="keyword">this</span>,<span class="string">'progress'</span>]);</span><br><span class="line">        <span class="comment">// ps: 如果目标网页跳转，也跟着跳转</span></span><br><span class="line">        <span class="comment">// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (<span class="literal">false</span> === ($stream = curl_exec($ch))) &#123;</span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> \Exception(curl_errno($ch));</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        curl_close($ch);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $stream;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 进度条下载.</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * @param $ch</span></span><br><span class="line"><span class="comment">     * @param $countDownloadSize    总下载量</span></span><br><span class="line"><span class="comment">     * @param $currentDownloadSize  当前下载量</span></span><br><span class="line"><span class="comment">     * @param $countUploadSize      </span></span><br><span class="line"><span class="comment">     * @param $currentUploadSize</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">progress</span>(<span class="params">$ch, $countDownloadSize, $currentDownloadSize, $countUploadSize, $currentUploadSize</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line"></span><br><span class="line">         <span class="comment">// 等于 0 的时候，应该是预读资源不等于0的时候即开始下载</span></span><br><span class="line">         <span class="comment">// 这里的每一个判断都是坑，多试试就知道了</span></span><br><span class="line">        <span class="keyword">if</span> (<span class="number">0</span> === $countDownloadSize) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 有时候会下载两次，第一次很小，应该是重定向下载</span></span><br><span class="line">        <span class="keyword">if</span> ($countDownloadSize &gt; $currentDownloadSize) &#123;</span><br><span class="line">            $<span class="keyword">this</span>-&gt;downloaded = <span class="literal">false</span>;</span><br><span class="line">            <span class="comment">// 继续显示进度条</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 已经下载完成还会再发三次请求</span></span><br><span class="line">        elseif ($<span class="keyword">this</span>-&gt;downloaded) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 两边相等下载完成并不一定结束，</span></span><br><span class="line">        elseif ($currentDownloadSize === $countDownloadSize) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 开始计算</span></span><br><span class="line">        $bar = $currentDownloadSize / $countDownloadSize * <span class="number">100</span>;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;bar-&gt;progress($bar);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">(<span class="keyword">new</span> Request)-&gt;download(<span class="string">'http://www.shiguopeng.cn/database.sql'</span>);</span><br><span class="line">http:<span class="comment">//www.shiguopeng.cn/archives/249</span></span><br></pre></td></tr></table></figure>
<h3 id="bindParam的绑定参数是引用"><a href="#bindParam的绑定参数是引用" class="headerlink" title="bindParam的绑定参数是引用"></a>bindParam的绑定参数是引用</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">    * $dbh是pdo实例化后的对象的句柄。</span></span><br><span class="line"><span class="comment">    * 第二个参数格式必须与第一个参数对应</span></span><br><span class="line"><span class="comment">    * $db-&gt;paramBindExec("select user_name, notes from message where user_name=:user_name", array(':user_name'=&gt;'guest'), false);</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">    * @param string $sql 预执行的SQL语句</span></span><br><span class="line"><span class="comment">    * @param array $param SQL参数绑定</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">    private <span class="function"><span class="keyword">function</span> <span class="title">paramBindExec</span>(<span class="params">$sql, $param</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">try</span></span><br><span class="line">        &#123;</span><br><span class="line">            $<span class="keyword">this</span>-&gt;statement = $<span class="keyword">this</span>-&gt;dbh-&gt;prepare($sql);</span><br><span class="line">            <span class="comment">// 绑定参数</span></span><br><span class="line">            <span class="keyword">if</span> (!empty($param))</span><br><span class="line">            &#123;</span><br><span class="line">                foreach ($param <span class="keyword">as</span> $key =&gt; $value)</span><br><span class="line">                &#123;</span><br><span class="line">                     <span class="comment">// 错误的写法</span></span><br><span class="line">                     <span class="comment">// $this-&gt;statement-&gt;bindParam($key, $value);</span></span><br><span class="line">                     <span class="comment">// 正确的写法</span></span><br><span class="line">                     $<span class="keyword">this</span>-&gt;statement-&gt;bindParam($key, $param[$key]);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">             <span class="comment">// 遗留下来的$value将会被引用最后一次的值</span></span><br><span class="line">             <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;statement-&gt;execute();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">catch</span> (PDOException $e)</span><br><span class="line">        &#123;</span><br><span class="line">             $<span class="keyword">this</span>-&gt;error_num = $e-&gt;getCode();</span><br><span class="line">             $<span class="keyword">this</span>-&gt;error_message =  $e-&gt;getMessage();</span><br><span class="line"></span><br><span class="line">             <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">         &#125;</span><br><span class="line">    &#125;</span><br><span class="line">绑定一个PHP变量到用作预处理的SQL语句中的对应命名占位符或问号占位符。 不同于PDOStatement::bindValue()，此 变量作为引用被绑定，并只在PDOStatement::execute()被调用的时候才取其值</span><br><span class="line">看到引用二字方醒悟，并不是循环一次，绑定一次参数。而是循环所有次数，才将参数绑定上去。而我绑定的变量每一次都是$value。</span><br><span class="line">最后将$value改成$param[$key]即可  http:<span class="comment">//www.shiguopeng.cn/archives/28</span></span><br></pre></td></tr></table></figure>
<h3 id="寻找数组中重复的值"><a href="#寻找数组中重复的值" class="headerlink" title="寻找数组中重复的值"></a>寻找数组中重复的值</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">FetchRepeatMemberInArray</span>(<span class="params">$array</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// 获取去掉重复数据的数组</span></span><br><span class="line">    $unique_arr = array_unique ( $array );</span><br><span class="line">    <span class="comment">// 获取重复数据的数组</span></span><br><span class="line">    $repeat_arr = array_diff_assoc ( $array, $unique_arr );</span><br><span class="line">    $repeat_arr = array_unique ( $repeat_arr );</span><br><span class="line">    <span class="keyword">return</span> $repeat_arr;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="php-redis-lua"><a href="#php-redis-lua" class="headerlink" title="php+redis+lua"></a>php+redis+lua</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">eval</span> <span class="string">"return &#123;KEYS[1],KEYS[2],ARGV[1],ARGV[2]&#125;"</span> <span class="number">2</span> key1 key2 first second</span><br><span class="line">$lua = <span class="string">"return &#123;KEYS[1],KEYS[2],ARGV[1],ARGV[2]&#125;"</span>;</span><br><span class="line">$s = $redis-&gt;<span class="built_in">eval</span>($lua,array(<span class="string">'key1'</span>,<span class="string">'key2'</span>,<span class="string">'first'</span>,<span class="string">'second'</span>),<span class="number">2</span>);</span><br><span class="line">$lua = <span class="string">"local ret=&#123;&#125;; for i,v in pairs(KEYS) do ret[i]=redis.call('hgetall', v) end; return ret"</span>;</span><br><span class="line">$obj = <span class="keyword">new</span> Dao_RedisBase();</span><br><span class="line">$arr_hash_key = [<span class="string">'hash1'</span>,<span class="string">'hash2'</span>,<span class="string">'hash3'</span>,<span class="string">'hash4'</span>];</span><br><span class="line">$hashresult=$obj-&gt;getCon()-&gt;<span class="built_in">eval</span>($lua,$arr_hash_key,count($arr_hash_key));</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> redis.call(<span class="string">"get"</span>,KEYS[<span class="number">1</span>]) == ARGV[<span class="number">1</span>] then</span><br><span class="line">    <span class="keyword">return</span> redis.call(<span class="string">"del"</span>,KEYS[<span class="number">1</span>])</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span></span><br><span class="line">end</span><br><span class="line">https:<span class="comment">//bettercuicui.github.io/2017/07/04/REDIS/php+redis+lua/</span></span><br></pre></td></tr></table></figure>
<h3 id="ob缓存"><a href="#ob缓存" class="headerlink" title="ob缓存"></a>ob缓存</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">ob_start();</span><br><span class="line">echo <span class="string">"aaa"</span>;</span><br><span class="line">header(<span class="string">'Content-Type:text/html;charset=utf-8'</span>);</span><br><span class="line">echo <span class="string">"bbb"</span>;</span><br><span class="line">$i =<span class="number">1</span>;</span><br><span class="line"><span class="keyword">while</span>($i&lt;<span class="number">5</span>)&#123;</span><br><span class="line">    echo $i++;</span><br><span class="line">    sleep(<span class="number">1</span>);</span><br><span class="line">&#125;</span><br><span class="line">$i =<span class="number">1</span>;</span><br><span class="line"><span class="keyword">while</span>($i&lt;<span class="number">5</span>)&#123;</span><br><span class="line">    echo $i++;</span><br><span class="line">    flush();</span><br><span class="line">    sleep(<span class="number">1</span>);</span><br><span class="line">&#125;</span><br><span class="line">flush()这个函数会把程序缓存的内容输出到浏览器中，并且清空程序缓存区的内容。这样就可以做到<span class="number">1</span><span class="number">-5</span>依次输出到屏幕，每次sleep1秒啦。</span><br><span class="line">ob_start(); <span class="comment">//打开缓冲区</span></span><br><span class="line">php页面的全部输出</span><br><span class="line">$content = ob_get_contents(); <span class="comment">//取得php页面输出的全部内容</span></span><br><span class="line">$fp = fopen(<span class="string">"output00001.html"</span>, <span class="string">"w"</span>); <span class="comment">//创建一个文件，并打开，准备写入</span></span><br><span class="line">fwrite($fp, $content); <span class="comment">//把php页面的内容全部写入output00001.html，然后……</span></span><br><span class="line">fclose($fp);</span><br><span class="line">https:<span class="comment">//bettercuicui.github.io/2016/11/29/PHP/%E7%BC%93%E5%AD%98%E6%80%BB%E7%BB%93/</span></span><br></pre></td></tr></table></figure>
<h3 id="不要直接克隆对象，请使用深拷贝"><a href="#不要直接克隆对象，请使用深拷贝" class="headerlink" title="不要直接克隆对象，请使用深拷贝"></a>不要直接克隆对象，请使用深拷贝</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"> final <span class="class"><span class="keyword">class</span> <span class="title">Car</span> </span>&#123;</span><br><span class="line">      public $model; <span class="comment">// 为了减少代码量，将其声明为公共方法</span></span><br><span class="line"></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">CarModel $model</span>) </span>&#123;</span><br><span class="line">         $<span class="keyword">this</span>-&gt;model = $model;</span><br><span class="line">     &#125; </span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line">final <span class="class"><span class="keyword">class</span> <span class="title">CarModel</span> </span>&#123;</span><br><span class="line">     public $name;</span><br><span class="line">     public $year;</span><br><span class="line"></span><br><span class="line">     public <span class="function"><span class="keyword">function</span> <span class="title">__construct</span>(<span class="params">$name, $year</span>) </span>&#123;</span><br><span class="line">        $<span class="keyword">this</span>-&gt;name = $name;</span><br><span class="line">         $<span class="keyword">this</span>-&gt;year = $year;</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br><span class="line"> $bmwX1 = <span class="keyword">new</span> Car(<span class="keyword">new</span> CarModel(<span class="string">'X1'</span>, <span class="number">2015</span>));</span><br><span class="line"> $bmwX5 = clone $bmwX1;</span><br><span class="line"> </span><br><span class="line">  var_dump(spl_object_hash($bmwX1)); <span class="comment">// "0000000037e353af0000558c268309ea"</span></span><br><span class="line"> var_dump(spl_object_hash($bmwX5)); <span class="comment">// "0000000037e353ac0000558c268309ea"</span></span><br><span class="line"> $bmwX5-&gt;model-&gt;name = <span class="string">'X5'</span>;</span><br><span class="line"> var_dump($bmwX1-&gt;model);</span><br><span class="line"> var_dump($bmwX5-&gt;model);</span><br><span class="line"> <span class="comment">// object(CarModel)#2 (2) &#123;</span></span><br><span class="line">  <span class="comment">//   ["name"]=&gt; "X5"</span></span><br><span class="line"> <span class="comment">//   ["year"]=&gt; int(2015)</span></span><br><span class="line">   <span class="comment">// &#125;</span></span><br><span class="line">   https:<span class="comment">//github.com/myclabs/DeepCopy</span></span><br><span class="line">    use <span class="function"><span class="keyword">function</span> <span class="title">DeepCopy</span>\<span class="title">deep_copy</span>;</span></span><br><span class="line"><span class="function">   </span></span><br><span class="line"><span class="function">   <span class="title">$bmwX1</span> = <span class="title">new</span> <span class="title">Car</span>(<span class="params">new CarModel(<span class="string">'X1'</span>, <span class="number">2015</span></span>));</span></span><br><span class="line"><span class="function">   <span class="title">$bmwX5</span> = <span class="title">deep_copy</span>(<span class="params">$bmwX1</span>);<span class="title">https</span>://<span class="title">learnku</span>.<span class="title">com</span>/<span class="title">php</span>/<span class="title">t</span>/37604</span></span><br></pre></td></tr></table></figure>
<h3 id="php请求接口异步化"><a href="#php请求接口异步化" class="headerlink" title="php请求接口异步化"></a>php请求接口异步化</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、用户每次请求删除的接口，直接把参数、操作保存在redis的list结构中。</span><br><span class="line"><span class="number">2</span>、crontable添加一个cron脚本，每分钟执行一次。</span><br><span class="line"><span class="number">3</span>、cron脚本读取redis的list，有值则fork出子进程进行操作。记得要set_time_limit();</span><br><span class="line"><span class="number">4</span>、如果cron脚本读取出list中的值，可以先标记一下，表示有脚本正在执行这个操作，如果执行失败还可以把这个任务塞回去再次执行。</span><br><span class="line"><span class="number">5</span>、当cron脚本再次发现list有值，先判断有没有脚本正在执行这个操作，有则不管了。</span><br><span class="line">如果php的执行方式是fastcgi，则有fastcgi_finish_request这个api。此函数冲刷(flush)所有响应的数据给客户端并结束请求。这使得客户端结束连接后，需要大量时间运行的任务能够继续运行。</span><br><span class="line">echo <span class="string">"正在进行删除操作，请稍后"</span>;</span><br><span class="line">fastcgi_finish_request();</span><br><span class="line"><span class="keyword">for</span>($i = <span class="number">1</span><span class="number">-10000</span>)&#123;</span><br><span class="line">    删除uid = $i的数据；</span><br><span class="line">&#125;用户通过浏览器请求删除的操作，立马收到’正在进行删除操作，请稍后’的提示，但是数据并没有被删除完，等<span class="number">50</span>s后，才发现数据被删除完毕。由此说明在调用fastcgi_finish_request后,客户端响应就已经结束,但与此同时服务端脚本却继续运行！</span><br><span class="line">https:<span class="comment">//bettercuicui.github.io/2018/04/01/PHP/php%E8%AF%B7%E6%B1%82%E6%8E%A5%E5%8F%A3%E5%BC%82%E6%AD%A5%E5%8C%96%20/</span></span><br></pre></td></tr></table></figure>
<h3 id="人民币小写转大写"><a href="#人民币小写转大写" class="headerlink" title="人民币小写转大写"></a>人民币小写转大写</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 人民币小写转大写</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * @param string $number      数值</span></span><br><span class="line"><span class="comment"> * @param string $intUnit     币种单位，默认"元"</span></span><br><span class="line"><span class="comment"> * @param bool   $isRound     是否对小数进行四舍五入</span></span><br><span class="line"><span class="comment"> * @param bool   $isExtraZero 是否对整数部分以0结尾，小数存在的数字附加0,比如1960.30，</span></span><br><span class="line"><span class="comment"> *                            有的需要输出"壹仟玖佰陆拾元零叁角"，实际上"壹仟玖佰陆拾元叁角"也是对的，随意，默认第一种</span></span><br><span class="line"><span class="comment"> * @return string</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">formatMoney</span>(<span class="params">$number, $intUnit = <span class="string">'元'</span>, $isRound = true, $isExtraZero = true</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $money = $number / <span class="number">100</span>;</span><br><span class="line">    $parts = explode(<span class="string">'.'</span>, $money, <span class="number">2</span>);</span><br><span class="line">    $int   = isset($parts[<span class="number">0</span>]) ? strval($parts[<span class="number">0</span>]) : <span class="string">'0'</span>;</span><br><span class="line">    $dec   = isset($parts[<span class="number">1</span>]) ? strval($parts[<span class="number">1</span>]) : <span class="string">''</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 如果小数点后多于2位，不四舍五入就直接截，否则就处理</span></span><br><span class="line">    $decLen = strlen($dec);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (isset($parts[<span class="number">1</span>]) &amp;&amp; $decLen &gt; <span class="number">2</span>) &#123;</span><br><span class="line">        $dec = $isRound</span><br><span class="line">                ? substr(strrchr(strval(round(floatval(<span class="string">"0."</span>.$dec), <span class="number">2</span>)), <span class="string">'.'</span>), <span class="number">1</span>)</span><br><span class="line">                : substr($parts[<span class="number">1</span>], <span class="number">0</span>, <span class="number">2</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 当number为0.001时，小数点后的金额为0元</span></span><br><span class="line">    <span class="keyword">if</span> (empty($int) &amp;&amp; empty($dec)) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">'零'</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 定义</span></span><br><span class="line">    $chs     = [<span class="string">'0'</span>,<span class="string">'壹'</span>,<span class="string">'贰'</span>,<span class="string">'叁'</span>,<span class="string">'肆'</span>,<span class="string">'伍'</span>,<span class="string">'陆'</span>,<span class="string">'柒'</span>,<span class="string">'捌'</span>,<span class="string">'玖'</span>];</span><br><span class="line">    $uni     = [<span class="string">''</span>,<span class="string">'拾'</span>,<span class="string">'佰'</span>,<span class="string">'仟'</span>];</span><br><span class="line">    $decUnit = [<span class="string">'角'</span>, <span class="string">'分'</span>];</span><br><span class="line">    $exp     = [<span class="string">''</span>, <span class="string">'万'</span>];</span><br><span class="line">    $res     = <span class="string">''</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 整数部分从右向左找</span></span><br><span class="line">    <span class="keyword">for</span> ($i = strlen($int) - <span class="number">1</span>, $k = <span class="number">0</span>; $i &gt;= <span class="number">0</span>; $k++) &#123;</span><br><span class="line">        $str = <span class="string">''</span>;</span><br><span class="line">        <span class="comment">// 按照中文读写习惯，每4个字为一段进行转化，i一直在减</span></span><br><span class="line">        <span class="keyword">for</span> ($j = <span class="number">0</span>; $j &lt; <span class="number">4</span> &amp;&amp; $i &gt;= <span class="number">0</span>; $j++, $i--) &#123;</span><br><span class="line">            $u   = $int&#123;$i&#125; &gt; <span class="number">0</span> ? $uni[$j] : <span class="string">''</span>;</span><br><span class="line">            $str = $chs[$int&#123;$i&#125;] . $u . $str;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        $str = rtrim($str, <span class="string">'0'</span>);</span><br><span class="line">        $str = preg_replace(<span class="string">"/0+/"</span>, <span class="string">"零"</span>, $str);</span><br><span class="line">        <span class="keyword">if</span> (!isset($exp[$k])) &#123;</span><br><span class="line">            $exp[$k] = $exp[$k - <span class="number">2</span>] . <span class="string">'亿'</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $u2  = $str != <span class="string">''</span> ? $exp[$k] : <span class="string">''</span>;</span><br><span class="line">        $res = $str . $u2 . $res;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 如果小数部分处理完之后是00，需要处理下</span></span><br><span class="line">    $dec = rtrim($dec, <span class="string">'0'</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 小数部分从左向右找</span></span><br><span class="line">    <span class="keyword">if</span> (!empty($dec)) &#123;</span><br><span class="line">        $res .= $intUnit;</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 是否要在整数部分以0结尾的数字后附加0，有的系统有这要求</span></span><br><span class="line">        <span class="keyword">if</span> ($isExtraZero) &#123;</span><br><span class="line">            <span class="keyword">if</span> (substr($int, <span class="number">-1</span>) === <span class="string">'0'</span>) &#123;</span><br><span class="line">                $res.= <span class="string">'零'</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>, $cnt = strlen($dec); $i &lt; $cnt; $i++) &#123;</span><br><span class="line">            $u = $dec&#123;$i&#125; &gt; <span class="number">0</span> ? $decUnit[$i] : <span class="string">''</span>;</span><br><span class="line">            $res .= $chs[$dec&#123;$i&#125;] . $u;</span><br><span class="line">        &#125;</span><br><span class="line">        $res = rtrim($res, <span class="string">'0'</span>);</span><br><span class="line">        $res = preg_replace(<span class="string">"/0+/"</span>, <span class="string">"零"</span>, $res);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        $res .= $intUnit . <span class="string">'整'</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> $res;</span><br><span class="line">&#125;https:<span class="comment">//blog.11010.net/archives/9/</span></span><br></pre></td></tr></table></figure>
<h3 id="不用内置函数取代var-dump"><a href="#不用内置函数取代var-dump" class="headerlink" title="不用内置函数取代var_dump()"></a>不用内置函数取代var_dump()</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">dump</span>(<span class="params">$var, $label = <span class="string">''</span>, $return = false</span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(ini_get(<span class="string">'html_errors'</span>))&#123;</span><br><span class="line">        $content = <span class="string">"&lt;pre&gt;\n"</span>;</span><br><span class="line">        <span class="keyword">if</span>($label != <span class="string">''</span>)&#123;</span><br><span class="line">            $content .= <span class="string">"&lt;strong&gt;&#123;$label&#125;&lt;/strong&gt;\n"</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        $content .= htmlspecialchars(print_r($<span class="keyword">var</span>, <span class="literal">true</span>));</span><br><span class="line">        $content .= <span class="string">"\n&lt;/pre&gt;\n"</span>;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        $content .= $label . <span class="string">":\n"</span> . print_r($<span class="keyword">var</span>,<span class="literal">true</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>($<span class="keyword">return</span>) <span class="keyword">return</span> $content;</span><br><span class="line">    echo $content;</span><br><span class="line">    <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="json转换"><a href="#json转换" class="headerlink" title="json转换"></a>json转换</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//3v4l.org/JSStn</span></span><br><span class="line">&lt;?php</span><br><span class="line"></span><br><span class="line">$json_str=<span class="string">'&#123;</span></span><br><span class="line"><span class="string">    "code": 200,</span></span><br><span class="line"><span class="string">    "message": "操作成功",</span></span><br><span class="line"><span class="string">    "data": [</span></span><br><span class="line"><span class="string">        &#123;</span></span><br><span class="line"><span class="string">            "id": 1,</span></span><br><span class="line"><span class="string">            "goods_id": 1,</span></span><br><span class="line"><span class="string">            "property_name_id": 1,</span></span><br><span class="line"><span class="string">            "property_value_id": 1,</span></span><br><span class="line"><span class="string">            "property_name": &#123;</span></span><br><span class="line"><span class="string">                "title": "份量",</span></span><br><span class="line"><span class="string">                "is_sale": true</span></span><br><span class="line"><span class="string">            &#125;,</span></span><br><span class="line"><span class="string">            "property_value": &#123;</span></span><br><span class="line"><span class="string">                "id": 1,</span></span><br><span class="line"><span class="string">                "value": "小份",</span></span><br><span class="line"><span class="string">                "image": ""</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;,</span></span><br><span class="line"><span class="string">        &#123;</span></span><br><span class="line"><span class="string">            "id": 2,</span></span><br><span class="line"><span class="string">            "goods_id": 1,</span></span><br><span class="line"><span class="string">            "property_name_id": 1,</span></span><br><span class="line"><span class="string">            "property_value_id": 2,</span></span><br><span class="line"><span class="string">            "property_name": &#123;</span></span><br><span class="line"><span class="string">                "title": "份量",</span></span><br><span class="line"><span class="string">                "is_sale": true</span></span><br><span class="line"><span class="string">            &#125;,</span></span><br><span class="line"><span class="string">            "property_value": &#123;</span></span><br><span class="line"><span class="string">                "id": 2,</span></span><br><span class="line"><span class="string">                "value": "中份",</span></span><br><span class="line"><span class="string">                "image": ""</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;,</span></span><br><span class="line"><span class="string">        &#123;</span></span><br><span class="line"><span class="string">            "id": 3,</span></span><br><span class="line"><span class="string">            "goods_id": 1,</span></span><br><span class="line"><span class="string">            "property_name_id": 2,</span></span><br><span class="line"><span class="string">            "property_value_id": 4,</span></span><br><span class="line"><span class="string">            "property_name": &#123;</span></span><br><span class="line"><span class="string">                "title": "温度",</span></span><br><span class="line"><span class="string">                "is_sale": true</span></span><br><span class="line"><span class="string">            &#125;,</span></span><br><span class="line"><span class="string">            "property_value": &#123;</span></span><br><span class="line"><span class="string">                "id": 4,</span></span><br><span class="line"><span class="string">                "value": "常温",</span></span><br><span class="line"><span class="string">                "image": ""</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;,</span></span><br><span class="line"><span class="string">        &#123;</span></span><br><span class="line"><span class="string">            "id": 4,</span></span><br><span class="line"><span class="string">            "goods_id": 1,</span></span><br><span class="line"><span class="string">            "property_name_id": 2,</span></span><br><span class="line"><span class="string">            "property_value_id": 5,</span></span><br><span class="line"><span class="string">            "property_name": &#123;</span></span><br><span class="line"><span class="string">                "title": "温度",</span></span><br><span class="line"><span class="string">                "is_sale": true</span></span><br><span class="line"><span class="string">            &#125;,</span></span><br><span class="line"><span class="string">            "property_value": &#123;</span></span><br><span class="line"><span class="string">                "id": 5,</span></span><br><span class="line"><span class="string">                "value": "加冰",</span></span><br><span class="line"><span class="string">                "image": ""</span></span><br><span class="line"><span class="string">            &#125;</span></span><br><span class="line"><span class="string">        &#125;</span></span><br><span class="line"><span class="string">    ]</span></span><br><span class="line"><span class="string">&#125;'</span>;</span><br><span class="line"> $obj = json_decode($json_str);</span><br><span class="line"></span><br><span class="line"> $data = [];</span><br><span class="line"> foreach($obj-&gt;data <span class="keyword">as</span> $v)&#123;</span><br><span class="line"></span><br><span class="line">   $nid=$v-&gt;property_name_id;</span><br><span class="line">   <span class="keyword">if</span>(!array_key_exists($nid,$data))&#123;</span><br><span class="line">       $o = <span class="keyword">new</span> stdclass;<span class="comment">//new Class&#123;&#125;</span></span><br><span class="line">       $o-&gt;property_id = $v-&gt;property_name_id;</span><br><span class="line">       $o-&gt;property_name = $v-&gt;property_name-&gt;title;</span><br><span class="line">       $o-&gt;is_sale= $v-&gt;property_name-&gt;is_sale ;</span><br><span class="line">       $data[$nid]=$o;</span><br><span class="line">   &#125;</span><br><span class="line">   $data[$nid]-&gt;items[]=$v-&gt;property_value;</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> $obj-&gt;data = array_values($data);</span><br><span class="line"> print_r($obj);</span><br><span class="line"> <span class="comment">//echo json_encode($obj); https://learnku.com/articles/37803#reply121107</span></span><br></pre></td></tr></table></figure>
<h3 id="无限级菜单排序"><a href="#无限级菜单排序" class="headerlink" title="无限级菜单排序"></a>无限级菜单排序</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">$temp = [</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">1</span>, <span class="string">'pid'</span> =&gt; <span class="number">0</span>, <span class="string">'name'</span> =&gt; <span class="string">'商品管理'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">2</span>, <span class="string">'pid'</span> =&gt; <span class="number">1</span>, <span class="string">'name'</span> =&gt; <span class="string">'平台自营'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">3</span>, <span class="string">'pid'</span> =&gt; <span class="number">2</span>, <span class="string">'name'</span> =&gt; <span class="string">'图书品类'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">4</span>, <span class="string">'pid'</span> =&gt; <span class="number">2</span>, <span class="string">'name'</span> =&gt; <span class="string">'3C品类'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">5</span>, <span class="string">'pid'</span> =&gt; <span class="number">0</span>, <span class="string">'name'</span> =&gt; <span class="string">'第三方'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">6</span>, <span class="string">'pid'</span> =&gt; <span class="number">5</span>, <span class="string">'name'</span> =&gt; <span class="string">'家私用品'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">7</span>, <span class="string">'pid'</span> =&gt; <span class="number">5</span>, <span class="string">'name'</span> =&gt; <span class="string">'书法品赏'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">8</span>, <span class="string">'pid'</span> =&gt; <span class="number">7</span>, <span class="string">'name'</span> =&gt; <span class="string">'行书'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">9</span>, <span class="string">'pid'</span> =&gt; <span class="number">8</span>, <span class="string">'name'</span> =&gt; <span class="string">'行楷'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">10</span>, <span class="string">'pid'</span> =&gt; <span class="number">9</span>, <span class="string">'name'</span> =&gt; <span class="string">'张山行楷字帖'</span>],</span><br><span class="line">        [<span class="string">'id'</span> =&gt; <span class="number">11</span>, <span class="string">'pid'</span> =&gt; <span class="number">22</span>, <span class="string">'name'</span> =&gt; <span class="string">'李四行楷字帖'</span>],</span><br><span class="line">    ];</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">te</span>(<span class="params">array $arr, $node = <span class="number">0</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $tem = []; </span><br><span class="line">    foreach ($arr <span class="keyword">as</span> $val) &#123;</span><br><span class="line">        $pid = $val[<span class="string">'pid'</span>]; <span class="comment">// 当前菜单的父级ID</span></span><br><span class="line">        $id = $val[<span class="string">'id'</span>]; <span class="comment">// 当前菜单ID</span></span><br><span class="line">        <span class="comment">// 当前的父级ID和node节点匹配，说明当前子菜单属于node节点。</span></span><br><span class="line">        <span class="keyword">if</span> ($pid == $node) &#123; </span><br><span class="line">            $tem[$id] = $val; <span class="comment">// 保存当前的菜单。</span></span><br><span class="line">            $son = te($arr, $id); <span class="comment">// 递归 当前子菜单是否有子菜单？</span></span><br><span class="line">            <span class="comment">// 当有的时候，保存 。</span></span><br><span class="line">            <span class="keyword">if</span> (!empty($son)) &#123;</span><br><span class="line">                $tem[$id][<span class="string">'son'</span>] = $son;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $tem;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">show</span>(<span class="params">array $arr, $node = <span class="number">0</span></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    foreach ($arr <span class="keyword">as</span> $val) &#123;</span><br><span class="line">        <span class="keyword">if</span> ($val[<span class="string">'pid'</span>] == <span class="number">0</span>) &#123;</span><br><span class="line">            $node = <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $node; $i++) &#123;</span><br><span class="line">            echo <span class="string">'----'</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        echo $val[<span class="string">'name'</span>] . <span class="string">"\n"</span>;</span><br><span class="line">        <span class="keyword">if</span> (isset($val[<span class="string">'son'</span>])) &#123;</span><br><span class="line">            $node += <span class="number">1</span>;</span><br><span class="line">            show($val[<span class="string">'son'</span>], $node);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$menus = te($temp);</span><br><span class="line"> show($menus);</span><br><span class="line"> <span class="function"><span class="keyword">function</span> <span class="title">traverseMenu</span>(<span class="params">array $menus, array &amp;$result, $pid = <span class="number">0</span></span>)</span></span><br><span class="line"><span class="function"> </span>&#123;</span><br><span class="line">     foreach ($menus <span class="keyword">as</span> $child_menu) &#123;</span><br><span class="line">         <span class="keyword">if</span> ($child_menu[<span class="string">'pid'</span>] == $pid) &#123;</span><br><span class="line">             $item = [<span class="string">'id'</span> =&gt; $child_menu[<span class="string">'id'</span>], <span class="string">'name'</span> =&gt; $child_menu[<span class="string">'name'</span>], <span class="string">'children'</span> =&gt; []];</span><br><span class="line">             traverseMenu($menus, $item[<span class="string">'children'</span>], $child_menu[<span class="string">'id'</span>]);</span><br><span class="line">             $result[] = $item;</span><br><span class="line">         &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">             <span class="keyword">continue</span>;</span><br><span class="line">         &#125;</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br><span class="line"> </span><br><span class="line"> $result = [];</span><br><span class="line"> traverseMenu($temp, $result, <span class="number">0</span>);</span><br><span class="line"> https:<span class="comment">//learnku.com/laravel/t/37883</span></span><br></pre></td></tr></table></figure>
<h3 id="静态变量-缓存"><a href="#静态变量-缓存" class="headerlink" title="静态变量 缓存"></a>静态变量 缓存</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">getData</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">static</span> $data = [];</span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> (!$data) &#123;</span><br><span class="line">            $path = __DIR__.<span class="string">'/data.json'</span>;</span><br><span class="line">            $data  = json_decode(file_get_contents($path), <span class="literal">true</span>);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $data;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// info1.php</span></span><br><span class="line">$app = <span class="keyword">new</span> App;</span><br><span class="line">$info = $app-&gt;getData();</span><br><span class="line"></span><br><span class="line"><span class="comment">// info2.php</span></span><br><span class="line">$app = <span class="keyword">new</span> App;</span><br><span class="line">$info = $app-&gt;getData();</span><br><span class="line">https:<span class="comment">//learnku.com/lk/t/34710</span></span><br></pre></td></tr></table></figure>
<h3 id="composer-内存不足"><a href="#composer-内存不足" class="headerlink" title="composer 内存不足"></a>composer 内存不足</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">free -m</span><br><span class="line">              total        used        free      shared  buff/cache   available</span><br><span class="line">Mem:            <span class="number">864</span>         <span class="number">372</span>         <span class="number">306</span>          <span class="number">50</span>         <span class="number">185</span>         <span class="number">296</span></span><br><span class="line">Swap:             <span class="number">0</span>           <span class="number">0</span>           <span class="number">0</span></span><br><span class="line"># 如上发现Swap实际都为0</span><br><span class="line">/bin/dd <span class="keyword">if</span>=<span class="regexp">/dev/</span>zero <span class="keyword">of</span>=<span class="regexp">/var/</span>swap<span class="number">.1</span> bs=<span class="number">1</span>M count=<span class="number">1024</span></span><br><span class="line">/sbin/mkswap /<span class="keyword">var</span>/swap<span class="number">.1</span></span><br><span class="line">/sbin/swapon /<span class="keyword">var</span>/swap<span class="number">.1</span></span><br><span class="line"># 再次使用free -m，发现已经有了Swap内存配置</span><br><span class="line">              total        used        free      shared  buff/cache   available</span><br><span class="line">Mem:            <span class="number">864</span>         <span class="number">383</span>          <span class="number">67</span>          <span class="number">49</span>         <span class="number">413</span>         <span class="number">267</span></span><br><span class="line">Swap:          <span class="number">1023</span>           <span class="number">0</span>        <span class="number">1023</span></span><br><span class="line"># 再次运行composer install即可</span><br></pre></td></tr></table></figure>
<h3 id="PHP-仿-Word-统计文章字数"><a href="#PHP-仿-Word-统计文章字数" class="headerlink" title="PHP 仿 Word 统计文章字数"></a>PHP 仿 Word 统计文章字数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">comment_count_word</span>(<span class="params">$str</span>)</span>&#123;</span><br><span class="line">    <span class="comment">//$str =characet($str);</span></span><br><span class="line">    <span class="comment">//判断是否存在替换字符</span></span><br><span class="line">    $is_tihuan_count=substr_count($str,<span class="string">"龘"</span>);</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        <span class="comment">//先将回车换行符做特殊处理</span></span><br><span class="line">        $str = preg_replace(<span class="string">'/(\r\n+|\s+|　+)/'</span>,<span class="string">"龘"</span>,$str);</span><br><span class="line">        <span class="comment">//处理英文字符数字，连续字母、数字、英文符号视为一个单词</span></span><br><span class="line">        $str = preg_replace(<span class="string">'/[a-z_A-Z0-9-\.!@#\$%\\\^&amp;\*\)\(\+=\&#123;\&#125;\[\]\/",\'&lt;&gt;~`\?:;|]/'</span>,<span class="string">"m"</span>,$str);</span><br><span class="line">        <span class="comment">//合并字符m，连续字母、数字、英文符号视为一个单词</span></span><br><span class="line">        $str = preg_replace(<span class="string">'/m+/'</span>,<span class="string">"*"</span>,$str);</span><br><span class="line">        <span class="comment">//去掉回车换行符</span></span><br><span class="line">        $str = preg_replace(<span class="string">'/龘+/'</span>,<span class="string">""</span>,$str);</span><br><span class="line">        <span class="comment">//返回字数</span></span><br><span class="line">        <span class="keyword">return</span> mb_strlen($str)+$is_tihuan_count;</span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception $e) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;https:<span class="comment">//learnku.com/articles/37939</span></span><br></pre></td></tr></table></figure>
<h3 id="Tesseract-图片识别"><a href="#Tesseract-图片识别" class="headerlink" title="Tesseract 图片识别"></a>Tesseract 图片识别</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> thiagoalessio/tesseract_ocr</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ImageService</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">read</span>(<span class="params">string $url</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $path = $<span class="keyword">this</span>-&gt;save($url);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $<span class="keyword">this</span>-&gt;tesseract($path);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * @Task</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    public <span class="function"><span class="keyword">function</span> <span class="title">tesseract</span>(<span class="params">string $path</span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (<span class="keyword">new</span> TesseractOCR($path))-&gt;run();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    protected <span class="function"><span class="keyword">function</span> <span class="title">save</span>(<span class="params">string $url</span>): <span class="title">string</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        $client = di()-&gt;get(ClientFactory::<span class="class"><span class="keyword">class</span>)-&gt;<span class="title">create</span>()</span>;</span><br><span class="line">        $content = $client-&gt;get($url)-&gt;getBody()-&gt;getContents();</span><br><span class="line"></span><br><span class="line">        $path = BASE_PATH . <span class="string">'/runtime/'</span> . uniqid();</span><br><span class="line">        file_put_contents($path, $content);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> $path;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;https:<span class="comment">//learnku.com/articles/32096</span></span><br></pre></td></tr></table></figure>
<h3 id="imagepng-返回的图片流直接上传"><a href="#imagepng-返回的图片流直接上传" class="headerlink" title="imagepng 返回的图片流直接上传"></a>imagepng 返回的图片流直接上传</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">ob_start();</span><br><span class="line"></span><br><span class="line">imagepng($image_data);</span><br><span class="line"></span><br><span class="line">$string_data = ob_get_contents(); <span class="comment">// read from buffer</span></span><br><span class="line"></span><br><span class="line">ob_end_clean(); <span class="comment">// delete buffer</span></span><br><span class="line"></span><br><span class="line">Oss::uploadByString($string_data)</span><br><span class="line">https:<span class="comment">//learnku.com/php/t/38225</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP-方法重写"><a href="#PHP-方法重写" class="headerlink" title="PHP 方法重写"></a>PHP 方法重写</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">php 方法重写，参数不同，报错： Declaration <span class="keyword">of</span> should be compatible <span class="keyword">with</span> that</span><br><span class="line"></span><br><span class="line">Strict standards: Declaration <span class="keyword">of</span> ... should be compatible <span class="keyword">with</span> that <span class="keyword">of</span> ...</span><br><span class="line"></span><br><span class="line">解决方法：</span><br><span class="line"></span><br><span class="line">&lt;?php</span><br><span class="line">abstract <span class="class"><span class="keyword">class</span> <span class="title">A</span> </span>&#123;</span><br><span class="line"><span class="comment">// 方法无参数</span></span><br><span class="line">public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>)</span>&#123; echo <span class="string">'bar'</span>; &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">abstract <span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span> </span>&#123;</span><br><span class="line"><span class="comment">// 方法有参数</span></span><br><span class="line">public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params">$str = NULL</span>)</span>&#123; echo $str; &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/38351</span></span><br></pre></td></tr></table></figure>
<h3 id="最全的县级以上信息包"><a href="#最全的县级以上信息包" class="headerlink" title="最全的县级以上信息包"></a>最全的县级以上信息包</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">composer <span class="built_in">require</span> medz/gb-t<span class="number">-2260</span>^<span class="number">2.0</span></span><br><span class="line"></span><br><span class="line">$getter = \Medz\GBT2260\Getter::instance();</span><br><span class="line"></span><br><span class="line">## 获取一个代码的省信息</span><br><span class="line">$province = $getter-&gt;province(<span class="string">'511304'</span>); <span class="comment">// 四川省</span></span><br><span class="line"></span><br><span class="line">## 获取市级地区，注意，直辖地区是返回 null</span><br><span class="line">$city = $getter-&gt;city(<span class="string">'511304'</span>); <span class="comment">// 南充市</span></span><br><span class="line"></span><br><span class="line">## 获取区级地区</span><br><span class="line">$county = $getter-&gt;county(<span class="string">'511304'</span>); <span class="comment">// 嘉陵区</span></span><br><span class="line">https:<span class="comment">//github.com/medz/gb-t-2260</span></span><br></pre></td></tr></table></figure>
<h3 id="this、self、static-的区别"><a href="#this、self、static-的区别" class="headerlink" title="this、self、static 的区别"></a>this、self、static 的区别</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">$<span class="keyword">this</span> 调用类实例</span><br><span class="line"></span><br><span class="line">self 类自身</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> 调用类</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span> </span>&#123;</span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">         echo <span class="string">'A-foo&lt;br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span> <span class="keyword">extends</span> <span class="title">A</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        A::foo();  <span class="comment">// 结果：A-foo</span></span><br><span class="line">        <span class="keyword">static</span>::foo(); <span class="comment">// 结果：C-foo</span></span><br><span class="line">        self::foo(); <span class="comment">// 结果：B-foo</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        echo <span class="string">'B-foo&lt;br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span> <span class="keyword">extends</span> <span class="title">B</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    public <span class="keyword">static</span> <span class="function"><span class="keyword">function</span> <span class="title">foo</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        echo <span class="string">'C-foo&lt;br&gt;'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/38406</span></span><br><span class="line">C::test();</span><br></pre></td></tr></table></figure>
<h3 id="零宽空格"><a href="#零宽空格" class="headerlink" title="零宽空格"></a>零宽空格</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 正常的优惠券</span></span><br><span class="line">b4c44af562</span><br><span class="line"></span><br><span class="line"><span class="comment">// urlencode() 之后</span></span><br><span class="line">b4c44af562</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 有问题的优惠券</span></span><br><span class="line">b4c44af562​​​​​​​​​​​​​​</span><br><span class="line"></span><br><span class="line"><span class="comment">// urlencode() 之后</span></span><br><span class="line">b4c44af562%e2%<span class="number">80</span>%<span class="number">8</span>b%e2%<span class="number">80</span>%<span class="number">8</span>b%e2%<span class="number">80</span>%<span class="number">8</span>b%e2%<span class="number">80</span></span><br><span class="line">谷歌了下，这个东西叫做 零宽空格。一般的空格是有宽度的，使用光标可以将它选中。但零宽空格没有宽度，看不见，也难以选中，就像不存在一样。</span><br><span class="line">https:<span class="comment">//zh.wikipedia.org/wiki/%E9%9B%B6%E5%AE%BD%E7%A9%BA%E6%A0%BC</span></span><br><span class="line">http:<span class="comment">//sakyavarro.cn/post/%E9%9B%B6%E5%AE%BD%E7%A9%BA%E6%A0%BC</span></span><br><span class="line">控制台 </span><br><span class="line">copy(<span class="built_in">decodeURI</span>(<span class="string">'%E2%80%8B'</span>))</span><br></pre></td></tr></table></figure>
<h3 id="数组转utf-8"><a href="#数组转utf-8" class="headerlink" title="数组转utf-8"></a>数组转utf-8</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 数组转utf-8</span></span><br><span class="line"><span class="comment">     * @param string $data</span></span><br><span class="line"><span class="comment">     * @return array</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">function</span> <span class="title">gbk_to_utf8</span>(<span class="params">$data</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(is_array($data))&#123;</span><br><span class="line">            foreach($data <span class="keyword">as</span> $key =&gt; $value)&#123;</span><br><span class="line">                $data[$key]=call_user_func(__FUNCTION__,$value);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> $data;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> iconv(<span class="string">"gbk"</span>,<span class="string">"utf-8"</span>,$data);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">echo  date(<span class="string">'Y/m/d'</span>, strtotime(<span class="string">'last day of -1 month'</span>));</span><br><span class="line">echo  date(<span class="string">'Y/m/d'</span>, strtotime(<span class="string">'-1 month'</span>, strtotime(<span class="string">'2019/03/31'</span>)));</span><br><span class="line">today()-&gt;subMonthNoOverflow()</span><br></pre></td></tr></table></figure>
<h3 id="阿拉伯数字和中文数字的相互转换"><a href="#阿拉伯数字和中文数字的相互转换" class="headerlink" title="阿拉伯数字和中文数字的相互转换"></a>阿拉伯数字和中文数字的相互转换</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">numToWord</span>(<span class="params">$num</span>)</span>&#123;</span><br><span class="line">    $chiNum = array(<span class="string">'零'</span>, <span class="string">'一'</span>, <span class="string">'二'</span>, <span class="string">'三'</span>, <span class="string">'四'</span>, <span class="string">'五'</span>, <span class="string">'六'</span>, <span class="string">'七'</span>, <span class="string">'八'</span>, <span class="string">'九'</span>);</span><br><span class="line">    $chiUni = array(<span class="string">''</span>,<span class="string">'十'</span>, <span class="string">'百'</span>, <span class="string">'千'</span>, <span class="string">'万'</span>, <span class="string">'十'</span>, <span class="string">'百'</span>, <span class="string">'千'</span>, <span class="string">'亿'</span>);</span><br><span class="line">    $chiStr = <span class="string">''</span>;</span><br><span class="line">    $num_str = (string)$num;</span><br><span class="line">    $count = strlen($num_str);</span><br><span class="line">    $last_flag = <span class="literal">true</span>; <span class="comment">//上一个 是否为0</span></span><br><span class="line">    $zero_flag = <span class="literal">true</span>; <span class="comment">//是否第一个</span></span><br><span class="line">    $temp_num = <span class="literal">null</span>; <span class="comment">//临时数字</span></span><br><span class="line">    $chiStr = <span class="string">''</span>;<span class="comment">//拼接结果</span></span><br><span class="line">    <span class="keyword">if</span> ($count == <span class="number">2</span>) &#123;<span class="comment">//两位数</span></span><br><span class="line">        $temp_num = $num_str[<span class="number">0</span>];</span><br><span class="line">        $chiStr = $temp_num == <span class="number">1</span> ? $chiUni[<span class="number">1</span>] : $chiNum[$temp_num].$chiUni[<span class="number">1</span>];</span><br><span class="line">        $temp_num = $num_str[<span class="number">1</span>];</span><br><span class="line">        $chiStr .= $temp_num == <span class="number">0</span> ? <span class="string">''</span> : $chiNum[$temp_num]; </span><br><span class="line">    &#125;<span class="keyword">else</span> <span class="keyword">if</span>($count &gt; <span class="number">2</span>)&#123;</span><br><span class="line">        $index = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> ($i=$count<span class="number">-1</span>; $i &gt;= <span class="number">0</span> ; $i--) &#123; </span><br><span class="line">                $temp_num = $num_str[$i];</span><br><span class="line">                <span class="keyword">if</span> ($temp_num == <span class="number">0</span>) &#123;</span><br><span class="line">                    <span class="keyword">if</span> (!$zero_flag &amp;&amp; !$last_flag ) &#123;</span><br><span class="line">                        $chiStr = $chiNum[$temp_num]. $chiStr;</span><br><span class="line">                        $last_flag = <span class="literal">true</span>;</span><br><span class="line">                    &#125;</span><br><span class="line"></span><br><span class="line">                    <span class="keyword">if</span>($index == <span class="number">4</span> &amp;&amp; $temp_num == <span class="number">0</span>)&#123;</span><br><span class="line">                        $chiStr = <span class="string">"万"</span>.$chiStr;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                    <span class="keyword">if</span>($i == <span class="number">0</span> &amp;&amp; $temp_num == <span class="number">1</span> &amp;&amp; $index == <span class="number">1</span> &amp;&amp; $index == <span class="number">5</span>)&#123;</span><br><span class="line">                        $chiStr = $chiUni[$index%<span class="number">9</span>] .$chiStr;</span><br><span class="line">                    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">                        $chiStr = $chiNum[$temp_num].$chiUni[$index%<span class="number">9</span>] .$chiStr;</span><br><span class="line">                    &#125;</span><br><span class="line">                    $zero_flag = <span class="literal">false</span>;</span><br><span class="line">                    $last_flag = <span class="literal">false</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                $index ++;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        $chiStr = $chiNum[$num_str[<span class="number">0</span>]]; </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> $chiStr;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">cn2num</span>(<span class="params">$string</span>)</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(is_numeric($string))&#123;</span><br><span class="line">        <span class="keyword">return</span> $string;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// '仟' =&gt; '千','佰' =&gt; '百','拾' =&gt; '十',</span></span><br><span class="line">    $string = str_replace(<span class="string">'仟'</span>, <span class="string">'千'</span>, $string);</span><br><span class="line">    $string = str_replace(<span class="string">'佰'</span>, <span class="string">'百'</span>, $string);</span><br><span class="line">    $string = str_replace(<span class="string">'拾'</span>, <span class="string">'十'</span>, $string);</span><br><span class="line">    $num = <span class="number">0</span>;</span><br><span class="line">    $wan = explode(<span class="string">'万'</span>, $string);</span><br><span class="line">    <span class="keyword">if</span> (count($wan) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        $num += cn2num($wan[<span class="number">0</span>]) * <span class="number">10000</span>;</span><br><span class="line">        $string = $wan[<span class="number">1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    $qian = explode(<span class="string">'千'</span>, $string);</span><br><span class="line">    <span class="keyword">if</span> (count($qian) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        $num += cn2num($qian[<span class="number">0</span>]) * <span class="number">1000</span>;</span><br><span class="line">        $string = $qian[<span class="number">1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    $bai = explode(<span class="string">'百'</span>, $string);</span><br><span class="line">    <span class="keyword">if</span> (count($bai) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        $num += cn2num($bai[<span class="number">0</span>]) * <span class="number">100</span>;</span><br><span class="line">        $string = $bai[<span class="number">1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    $shi = explode(<span class="string">'十'</span>, $string);</span><br><span class="line">    <span class="keyword">if</span> (count($shi) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        $num += cn2num($shi[<span class="number">0</span>] ? $shi[<span class="number">0</span>] : <span class="string">'一'</span>) * <span class="number">10</span>;</span><br><span class="line">        $string = $shi[<span class="number">1</span>] ? $shi[<span class="number">1</span>] : <span class="string">'零'</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    $ling = explode(<span class="string">'零'</span>, $string);</span><br><span class="line">    <span class="keyword">if</span> (count($ling) &gt; <span class="number">1</span>) &#123;</span><br><span class="line">        $string = $ling[<span class="number">1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    $d = array(</span><br><span class="line">        <span class="string">'一'</span> =&gt; <span class="string">'1'</span>,<span class="string">'二'</span> =&gt; <span class="string">'2'</span>,<span class="string">'三'</span> =&gt; <span class="string">'3'</span>,<span class="string">'四'</span> =&gt; <span class="string">'4'</span>,<span class="string">'五'</span> =&gt; <span class="string">'5'</span>,<span class="string">'六'</span> =&gt; <span class="string">'6'</span>,<span class="string">'七'</span> =&gt; <span class="string">'7'</span>,<span class="string">'八'</span> =&gt; <span class="string">'8'</span>,<span class="string">'九'</span> =&gt; <span class="string">'9'</span>,</span><br><span class="line">        <span class="string">'壹'</span> =&gt; <span class="string">'1'</span>,<span class="string">'贰'</span> =&gt; <span class="string">'2'</span>,<span class="string">'叁'</span> =&gt; <span class="string">'3'</span>,<span class="string">'肆'</span> =&gt; <span class="string">'4'</span>,<span class="string">'伍'</span> =&gt; <span class="string">'5'</span>,<span class="string">'陆'</span> =&gt; <span class="string">'6'</span>,<span class="string">'柒'</span> =&gt; <span class="string">'7'</span>,<span class="string">'捌'</span> =&gt; <span class="string">'8'</span>,<span class="string">'玖'</span> =&gt; <span class="string">'9'</span>,</span><br><span class="line">        <span class="string">'零'</span> =&gt; <span class="number">0</span>, <span class="string">'0'</span> =&gt; <span class="number">0</span>, <span class="string">'O'</span> =&gt; <span class="number">0</span>, <span class="string">'o'</span> =&gt; <span class="number">0</span>,</span><br><span class="line">        <span class="string">'两'</span> =&gt; <span class="number">2</span></span><br><span class="line">    );</span><br><span class="line">    <span class="keyword">return</span> $num + @$d[$string];</span><br><span class="line">&#125;https:<span class="comment">//learnku.com/articles/39405</span></span><br></pre></td></tr></table></figure>
<h3 id="excel大数据导出"><a href="#excel大数据导出" class="headerlink" title="excel大数据导出"></a>excel大数据导出</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//https://github.com/Maatwebsite/Laravel-Excel</span></span><br><span class="line"><span class="comment">//不限制执行时间</span></span><br><span class="line">set_time_limit(<span class="number">0</span>);</span><br><span class="line"><span class="comment">//最大内存</span></span><br><span class="line">ini_set(<span class="string">'memory_limit'</span>, <span class="string">'-1'</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//导出txt逻辑</span></span><br><span class="line">$file_path = $file_name.<span class="string">".txt"</span>;</span><br><span class="line">$str = <span class="string">""</span>;<span class="comment">//拼接表头字符</span></span><br><span class="line">Storage::disk(<span class="string">'local'</span>)-&gt;put($file_path, $str);</span><br><span class="line"></span><br><span class="line"><span class="comment">//以二进制的方式追加读写</span></span><br><span class="line">$file = fopen(storage_path().$file_path, <span class="string">"a+b"</span>);</span><br><span class="line"></span><br><span class="line">$str = <span class="string">""</span>;</span><br><span class="line">$rows = [];<span class="comment">//数据源</span></span><br><span class="line">foreach ($rows <span class="keyword">as</span>  $row) &#123;</span><br><span class="line">    <span class="comment">//耗时处理操作得到$str</span></span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    <span class="comment">//每处理1条数据就写入一次，数据量大时，建议批量写入</span></span><br><span class="line">    fwrite($file, $str.<span class="string">"\n"</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">fclose($file);</span><br><span class="line">https:<span class="comment">//learnku.com/articles/38828#reply125534</span></span><br></pre></td></tr></table></figure>
<h3 id="bcadd-的精度"><a href="#bcadd-的精度" class="headerlink" title="bcadd 的精度"></a>bcadd 的精度</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、数值</span><br><span class="line"><span class="number">1</span>) <span class="number">4</span>位小数，且前<span class="number">4</span>位为<span class="number">0</span>的</span><br><span class="line">\Log::info(<span class="string">'bcadd:'</span> . bcadd(<span class="number">0.00002200</span>, <span class="number">0</span>, <span class="number">8</span>));</span><br><span class="line"><span class="comment">// 结果：bcadd:0.00000000</span></span><br><span class="line"><span class="number">2</span>) <span class="number">5</span>位小数，且前<span class="number">4</span>位有大于<span class="number">0</span>的</span><br><span class="line">\Log::info(<span class="string">'bcadd:'</span> . bcadd(<span class="number">0.00012200</span>, <span class="number">0</span>, <span class="number">8</span>));</span><br><span class="line"><span class="comment">// 结果：bcadd:0.00012200</span></span><br><span class="line"><span class="number">2</span>、字符串</span><br><span class="line">\Log::info(<span class="string">'bcadd:'</span> . bcadd(<span class="string">'0.00002200'</span>, <span class="number">0</span>, <span class="number">8</span>));</span><br><span class="line"><span class="comment">// 等同于 \Log::info('bcadd:' . bcadd((string)0.00012200, 0, 8)); </span></span><br><span class="line"><span class="comment">// 结果：bcadd:0.00002200</span></span><br><span class="line"><span class="number">3</span>、科学记数法</span><br><span class="line"><span class="number">1</span>) <span class="number">5</span>位小数，且前<span class="number">4</span>位有大于<span class="number">0</span>的</span><br><span class="line">\Log::info(<span class="string">'bcadd:'</span> . bcadd(<span class="number">2.2E-4</span>, <span class="number">0</span>, <span class="number">8</span>));</span><br><span class="line"><span class="comment">// 结果：bcadd:0.00022000</span></span><br><span class="line"><span class="number">2</span>) <span class="number">5</span>位小数，且第<span class="number">4</span>位等于<span class="number">0</span></span><br><span class="line">\Log::info(<span class="string">'bcadd:'</span> . bcadd(<span class="number">2.2E-5</span>, <span class="number">0</span>, <span class="number">8</span>));</span><br><span class="line"><span class="comment">// 结果：bcadd:0.00000000</span></span><br><span class="line"><span class="number">3</span>) <span class="number">5</span>为小数，第<span class="number">4</span>位大于<span class="number">0</span></span><br><span class="line">\Log::info(<span class="string">'bcadd:'</span> . bcadd(<span class="number">12.2E-5</span>, <span class="number">0</span>, <span class="number">8</span>));</span><br><span class="line"><span class="comment">// 结果：bcadd:0.00012200</span></span><br><span class="line">结论是超过 <span class="number">4</span> 位小数，且前 <span class="number">4</span> 位都为 <span class="number">0</span> 时，如不转为字符串进行 bcadd 计算，那么精度会有问题，结果会按 <span class="number">0</span> 来计算；高精度计算，建议先转为字符串再进行计算。</span><br><span class="line"></span><br><span class="line">根据需要，提前转为精度+<span class="number">1</span>的字符串类型参与计算，如需保留<span class="number">6</span>位，就取<span class="number">7</span>位出来</span><br><span class="line">$value = <span class="number">0.000011</span>;</span><br><span class="line">$value = sprintf(<span class="string">'%.7f'</span>, $value);</span><br><span class="line">保存数据时，可转再转为<span class="number">6</span>位</span><br><span class="line">$model-&gt;value = bcadd($value, <span class="number">0</span>, <span class="number">6</span>);</span><br><span class="line">$model-&gt;save();</span><br><span class="line">https:<span class="comment">//learnku.com/articles/39459</span></span><br></pre></td></tr></table></figure>
<h3 id="mysql-并发锁"><a href="#mysql-并发锁" class="headerlink" title="mysql 并发锁"></a>mysql 并发锁</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"> $process_num = <span class="number">50</span>; <span class="comment">//开50个进程，模拟50个用户</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $process_num; $i++) &#123;</span><br><span class="line">            MultiProcessHelper::instance($process_num)-&gt;multiProcessTask(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) <span class="title">use</span> (<span class="params">$i</span>) </span>&#123;</span><br><span class="line">                <span class="keyword">if</span> (Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;value(<span class="string">'count'</span>) &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                    $res = Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;setDec(<span class="string">'count'</span>);</span><br><span class="line">                    <span class="keyword">if</span> ($res) &#123;</span><br><span class="line">                        dump(<span class="string">'获取到更新资源权限：'</span> . $i);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">这就是高并发带来的问题，同一时刻有多个进程读取同一条数据，同一时刻有多个进程更新同一条数据</span><br><span class="line">mysql 提供的行级锁 select ... lock <span class="keyword">in</span> share mode（阻塞写），select ... for update（阻塞读写，悲观锁），所以 <span class="keyword">for</span> update 机制能满足我们的原子要求。编辑代码如下：</span><br><span class="line">        $process_num = <span class="number">50</span>; <span class="comment">//开50个进程，模拟50个用户</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $process_num; $i++) &#123;</span><br><span class="line">            MultiProcessHelper::instance($process_num)-&gt;multiProcessTask(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) <span class="title">use</span> (<span class="params">$i</span>) </span>&#123;</span><br><span class="line">                Db::startTrans(); <span class="comment">//行级锁必须在事务中才能生效</span></span><br><span class="line">                <span class="comment">//设置for update，进程会阻塞在这里，只能允许一个进程获取到行锁，其他等待获取</span></span><br><span class="line">                <span class="keyword">if</span> (Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;lock(<span class="string">'for update'</span>)-&gt;value(<span class="string">'count'</span>) &gt; <span class="number">0</span>) &#123; </span><br><span class="line">                    $res = Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;setDec(<span class="string">'count'</span>);</span><br><span class="line">                    <span class="keyword">if</span> ($res) &#123;</span><br><span class="line">                        dump(<span class="string">'获取到更新资源权限：'</span> . $i);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                Db::commit();</span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        update</span><br><span class="line">   $process_num = <span class="number">50</span>; <span class="comment">//开50个进程，模拟50个用户</span></span><br><span class="line">    <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $process_num; $i++) &#123;</span><br><span class="line">        MultiProcessHelper::instance($process_num)-&gt;multiProcessTask(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) <span class="title">use</span> (<span class="params">$i</span>) </span>&#123;</span><br><span class="line">                <span class="comment">//合并两条语句为一条更新语句</span></span><br><span class="line">                $res = Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;where(<span class="string">'count'</span>, <span class="string">'&gt;'</span>, <span class="number">0</span>)-&gt;setDec(<span class="string">'count'</span>);</span><br><span class="line">                <span class="keyword">if</span> ($res) &#123;</span><br><span class="line">                    dump(<span class="string">'获取到更新资源权限：'</span> . $i);</span><br><span class="line">                &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">文件锁</span><br><span class="line">  $process_num = <span class="number">50</span>; <span class="comment">//开50个进程，模拟50个用户</span></span><br><span class="line">        <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $process_num; $i++) &#123;</span><br><span class="line">            MultiProcessHelper::instance($process_num)-&gt;multiProcessTask(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) <span class="title">use</span> (<span class="params">$i</span>) </span>&#123;</span><br><span class="line">                $filename = app()-&gt;getRootPath() . <span class="string">'runtime/lock'</span>;</span><br><span class="line">                $file = fopen($filename, <span class="string">'w'</span>); <span class="comment">//打开文件</span></span><br><span class="line">                $lock = flock($file, LOCK_EX);</span><br><span class="line">                <span class="comment">// $lock=flock($handle, LOCK_EX|LOCK_NB); （异步非阻塞，所有进程如果出现获取不到锁，不等待跳过，加锁失败）</span></span><br><span class="line">                <span class="comment">//获取文件排他锁:LOCK_EX（异步阻塞，只有一个进程获得锁，其他竞争进程等待）</span></span><br><span class="line">                <span class="comment">//还有一种共享锁:LOCK_SH（所有进程都可以获取共享锁，读取文件，当且只有一个锁时，才允许写操作，否则操作失败，容易出现死锁问题）</span></span><br><span class="line">                <span class="keyword">if</span> ($lock) &#123;</span><br><span class="line">                    <span class="keyword">try</span> &#123;</span><br><span class="line">                        <span class="keyword">if</span> (Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;lock(<span class="string">'for update'</span>)-&gt;value(<span class="string">'count'</span>) &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                            $res = Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;setDec(<span class="string">'count'</span>);</span><br><span class="line">                            <span class="keyword">if</span> ($res) &#123;</span><br><span class="line">                                dump(<span class="string">'获取到更新资源权限：'</span> . $i);</span><br><span class="line">                            &#125;</span><br><span class="line">                        &#125;</span><br><span class="line">                    &#125; <span class="keyword">catch</span> (\Exception $e) &#123;</span><br><span class="line">                        dump($e-&gt;getMessage());</span><br><span class="line">                    &#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">                        flock($file, LOCK_UN); <span class="comment">//无论如何都要释放锁</span></span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">                fclose($file); <span class="comment">//关闭文件句柄</span></span><br><span class="line">            &#125;);</span><br><span class="line">        &#125;</span><br><span class="line">  在集群架构、分布式等多机联网结构中就是掩耳盗铃了，所以适应性更好地锁机制还是要使用分布式锁，分布式锁最常用和最易用就是 redis 的 setnx 锁了。</span><br><span class="line">  编辑代码如下：</span><br><span class="line">  </span><br><span class="line">          $process_num = <span class="number">50</span>; <span class="comment">//开50个进程，模拟50个用户</span></span><br><span class="line">          <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; $process_num; $i++) &#123;</span><br><span class="line">              MultiProcessHelper::instance($process_num)-&gt;multiProcessTask(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) <span class="title">use</span> (<span class="params">$i</span>) </span>&#123;</span><br><span class="line">                  <span class="comment">//获取redis锁</span></span><br><span class="line">                  <span class="comment">//关于CacheHelper::getRedisLock是怎样获取锁的，注意几个点就行：1.如何避免死锁；2.如何设置过期时间；3.如何设置抢占条件；4.如何循环等待判断。这些不在本文讨论范围，可自行研究，以后有空我也可以写一篇博文</span></span><br><span class="line">                  $lock = CacheHelper::getRedisLock(<span class="string">'redis_lock'</span>);</span><br><span class="line">                  <span class="keyword">if</span> ($lock) &#123;</span><br><span class="line">                      <span class="keyword">try</span> &#123;</span><br><span class="line">                          <span class="keyword">if</span> (Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;lock(<span class="string">'for update'</span>)-&gt;value(<span class="string">'count'</span>) &gt; <span class="number">0</span>) &#123;</span><br><span class="line">                              $res = Db::name(<span class="string">'product'</span>)-&gt;where(<span class="string">'id'</span>, <span class="number">1</span>)-&gt;setDec(<span class="string">'count'</span>);</span><br><span class="line">                              <span class="keyword">if</span> ($res) &#123;</span><br><span class="line">                                  dump(<span class="string">'获取到更新资源权限：'</span> . $i);</span><br><span class="line">                              &#125;</span><br><span class="line">                          &#125;</span><br><span class="line">                      &#125; <span class="keyword">catch</span> (\Exception $e) &#123;</span><br><span class="line">                          dump($e-&gt;getMessage());</span><br><span class="line">                      &#125;</span><br><span class="line">                  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">  <span class="comment">//                    dump('获取redis锁失败');</span></span><br><span class="line">                  &#125;</span><br><span class="line">              &#125;);</span><br><span class="line">          &#125;      </span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span>  https:<span class="comment">//learnku.com/articles/39244</span></span><br></pre></td></tr></table></figure>
<h3 id="并发下安全读写文件函数"><a href="#并发下安全读写文件函数" class="headerlink" title="并发下安全读写文件函数"></a>并发下安全读写文件函数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&lt;?php</span><br><span class="line"> </span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * @link http://kodcloud.com/</span></span><br><span class="line"><span class="comment"> * @author warlee | e-mail:kodcloud@qq.com</span></span><br><span class="line"><span class="comment"> * @copyright warlee 2014.(Shanghai)Co.,Ltd</span></span><br><span class="line"><span class="comment"> * @license http://kodcloud.com/tools/license/license.txt</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> https:<span class="comment">//mkblog.cn/1831/  孟坤大佬</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 安全读取文件，避免并发下读取数据为空</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * @param $file 要读取的文件路径</span></span><br><span class="line"><span class="comment"> * @param $timeout 读取超时时间 </span></span><br><span class="line"><span class="comment"> * @return 读取到的文件内容 | false - 读取失败</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">file_read_safe</span>(<span class="params">$file, $timeout = <span class="number">5</span></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!$file || !file_exists($file)) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    $fp = @fopen($file, <span class="string">'r'</span>);</span><br><span class="line">    <span class="keyword">if</span> (!$fp) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    $startTime = microtime(<span class="literal">true</span>);</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 在指定时间内完成对文件的独占锁定</span></span><br><span class="line">    <span class="keyword">do</span> &#123;</span><br><span class="line">        $locked = flock($fp, LOCK_EX | LOCK_NB);</span><br><span class="line">        <span class="keyword">if</span> (!$locked) &#123;</span><br><span class="line">            usleep(mt_rand(<span class="number">1</span>, <span class="number">50</span>) * <span class="number">1000</span>);     <span class="comment">// 随机等待1~50ms再试</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">while</span> ((!$locked) &amp;&amp; ((microtime(<span class="literal">true</span>) - $startTime) &lt; $timeout));</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> ($locked &amp;&amp; filesize($file) &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">        $result = @fread($fp, filesize($file));</span><br><span class="line">        flock($fp, LOCK_UN);</span><br><span class="line">        fclose($fp);</span><br><span class="line">        <span class="keyword">if</span> (filesize($file) == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> $result;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        flock($fp, LOCK_UN);</span><br><span class="line">        fclose($fp);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 安全写文件，避免并发下写入数据为空</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * @param $file 要写入的文件路径</span></span><br><span class="line"><span class="comment"> * @param $buffer 要写入的文件二进制流（文件内容）</span></span><br><span class="line"><span class="comment"> * @param $timeout 写入超时时间 </span></span><br><span class="line"><span class="comment"> * @return 写入的字符数 | false - 写入失败</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">file_write_safe</span>(<span class="params">$file, $buffer, $timeout = <span class="number">5</span></span>) </span>&#123;</span><br><span class="line">    clearstatcache();</span><br><span class="line">    <span class="keyword">if</span> (strlen($file) == <span class="number">0</span> || !$file) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 文件不存在则创建</span></span><br><span class="line">    <span class="keyword">if</span> (!file_exists($file)) &#123;</span><br><span class="line">        @file_put_contents($file, <span class="string">''</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(!is_writeable($file)) <span class="keyword">return</span> <span class="literal">false</span>;    <span class="comment">// 不可写</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 在指定时间内完成对文件的独占锁定</span></span><br><span class="line">    $fp = fopen($file, <span class="string">'r+'</span>);</span><br><span class="line">    $startTime = microtime(<span class="literal">true</span>);</span><br><span class="line">    <span class="keyword">do</span> &#123;</span><br><span class="line">        $locked = flock($fp, LOCK_EX); </span><br><span class="line">        <span class="keyword">if</span> (!$locked) &#123;</span><br><span class="line">            usleep(mt_rand(<span class="number">1</span>, <span class="number">50</span>) * <span class="number">1000</span>);   <span class="comment">// 随机等待1~50ms再试</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">while</span> ((!$locked) &amp;&amp; ((microtime(<span class="literal">true</span>) - $startTime) &lt; $timeout));    </span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span> ($locked) &#123;</span><br><span class="line">        $tempFile = $file.<span class="string">'.temp'</span>;</span><br><span class="line">        $result = file_put_contents($tempFile, $buffer, LOCK_EX);</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">if</span> (!$result || !file_exists($tempFile)) &#123;</span><br><span class="line">            flock($fp, LOCK_UN);</span><br><span class="line">            fclose($fp);</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        @unlink($tempFile);</span><br><span class="line">        </span><br><span class="line">        ftruncate($fp, <span class="number">0</span>);</span><br><span class="line">        rewind($fp);</span><br><span class="line">        $result = fwrite($fp, $buffer);</span><br><span class="line">        flock($fp, LOCK_UN);</span><br><span class="line">        fclose($fp);</span><br><span class="line">        clearstatcache();</span><br><span class="line">        <span class="keyword">return</span> $result;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        flock($fp, LOCK_UN);</span><br><span class="line">        fclose($fp);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="随机图像"><a href="#随机图像" class="headerlink" title="随机图像"></a>随机图像</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line">$img_array = glob(<span class="string">'images/*.&#123;gif,jpg,png,jpeg,webp,bmp&#125;'</span>, GLOB_BRACE);</span><br><span class="line"><span class="keyword">if</span>(count($img_array) == <span class="number">0</span>) die(<span class="string">'没找到图片文件。请先上传一些图片到 '</span>.dirname(__FILE__).<span class="string">'/images/ 文件夹'</span>);</span><br><span class="line">header(<span class="string">'Content-Type: image/png'</span>);</span><br><span class="line">echo(file_get_contents($img_array[array_rand($img_array)]));</span><br><span class="line">?&gt;</span><br><span class="line">https:<span class="comment">//mkblog.cn/1836/</span></span><br></pre></td></tr></table></figure>
<h3 id="PHP读取exe软件版本号"><a href="#PHP读取exe软件版本号" class="headerlink" title="PHP读取exe软件版本号"></a>PHP读取exe软件版本号</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * PHP 读取 exe\dll 文件版本号</span><br><span class="line"> * </span><br><span class="line"> * @auth   @腾讯电脑管家(https://zhidao.baidu.com/question/246143241010222924.html)</span><br><span class="line"> * @param  $filename 目标文件</span><br><span class="line"> * @return 读取到的版本号https://mkblog.cn/1712/</span><br><span class="line"> */</span><br><span class="line">function getFileVersion($filename)</span><br><span class="line">&#123;</span><br><span class="line">    $fileversion = &apos;&apos;;</span><br><span class="line">    $fpFile = @fopen($filename, &quot;rb&quot;);</span><br><span class="line">    $strFileContent = @fread($fpFile, filesize($filename));</span><br><span class="line">    fclose($fpFile);</span><br><span class="line">    if($strFileContent)</span><br><span class="line">    &#123;</span><br><span class="line">        $strTagBefore = &apos;F\0i\0l\0e\0V\0e\0r\0s\0i\0o\0n\0\0\0\0\0&apos;;        // 如果使用这行，读取的是 FileVersion</span><br><span class="line">        // $strTagBefore = &apos;P\0r\0o\0d\0u\0c\0t\0V\0e\0r\0s\0i\0o\0n\0\0&apos;;    // 如果使用这行，读取的是 ProductVersion</span><br><span class="line">        $strTagAfter = &apos;\0\0&apos;;</span><br><span class="line">        if (preg_match(&quot;/$strTagBefore(.*?)$strTagAfter/&quot;, $strFileContent, $arrMatches))</span><br><span class="line">        &#123;</span><br><span class="line">            if(count($arrMatches) == 2) </span><br><span class="line">            &#123;</span><br><span class="line">                $fileversion = str_replace(&quot;\0&quot;, &apos;&apos;, $arrMatches[1]);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return $fileversion;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="百度当图床"><a href="#百度当图床" class="headerlink" title="百度当图床"></a>百度当图床</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">&lt;?php</span><br><span class="line"> </span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 上传图片到百度识图接口，获取图片外链</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * @param     $file 图片文件</span></span><br><span class="line"><span class="comment"> * @return    图片链接(上传成功)    NULL(上传失败)</span></span><br><span class="line"><span class="comment"> * @copyright (c) mengkun(https://mkblog.cn/1619/)</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">uploadToBaidu</span>(<span class="params">$file</span>) </span>&#123;</span><br><span class="line">    <span class="comment">// API 接口地址</span></span><br><span class="line">    $url = <span class="string">'http://image.baidu.com/pcdutu/a_upload?fr=html5&amp;target=pcSearchImage&amp;needJson=true'</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 文件不存在</span></span><br><span class="line">    <span class="keyword">if</span>(!file_exists($file)) <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// POST 文件</span></span><br><span class="line">    <span class="keyword">if</span> (class_exists(<span class="string">'CURLFile'</span>)) &#123;     <span class="comment">// php 5.5</span></span><br><span class="line">        $post[<span class="string">'file'</span>] = <span class="keyword">new</span> CURLFile(realpath($file));</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        $post[<span class="string">'file'</span>] = <span class="string">'@'</span>.realpath($file);</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// CURL 模拟提交</span></span><br><span class="line">    $ch = curl_init();</span><br><span class="line">    curl_setopt($ch, CURLOPT_URL , $url);</span><br><span class="line">    curl_setopt($ch, CURLOPT_RETURNTRANSFER, <span class="number">1</span>);</span><br><span class="line">    curl_setopt($ch, CURLOPT_POST, <span class="number">1</span>);</span><br><span class="line">    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);</span><br><span class="line">    $output = curl_exec($ch);</span><br><span class="line">    curl_close($ch);</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 返回结果为空（上传失败）</span></span><br><span class="line">    <span class="keyword">if</span>($output == <span class="string">''</span>) <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 解析数据</span></span><br><span class="line">    $output = json_decode($output, <span class="literal">true</span>);</span><br><span class="line">    <span class="keyword">if</span>(isset($output[<span class="string">'url'</span>]) &amp;&amp; $output[<span class="string">'url'</span>] != <span class="string">''</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> $output[<span class="string">'url'</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">''</span>;</span><br><span class="line">&#125;</span><br><span class="line"> 在获取到的链接前面加上</span><br><span class="line"> https:<span class="comment">//image.baidu.com/search/down?tn=download&amp;url=</span></span><br><span class="line"> 可以绕过防盗链，并且 https 一步到位</span><br><span class="line"><span class="comment">// 使用示例：https://mkblog.cn/1619/comment-page-1/#comments</span></span><br><span class="line">$url = uploadToBaidu(<span class="string">'1.jpg'</span>);</span><br><span class="line">echo $url;</span><br></pre></td></tr></table></figure>
<h3 id="变量的作用域"><a href="#变量的作用域" class="headerlink" title="变量的作用域"></a>变量的作用域</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">方法一：使用 global 关键字</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">updateCounter</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    global $counter;</span><br><span class="line">    $counterr++;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$counter = <span class="number">10</span>;</span><br><span class="line">updateCounter();</span><br><span class="line">echo $counter; <span class="comment">// 11</span></span><br><span class="line">方法二：使用 PHP 中的 $GLOBALS 数组https:<span class="comment">//learnku.com/articles/39670</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">updateCounter</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    $GLOBALS[counter]++:</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$counter = <span class="number">10</span>;</span><br><span class="line">updateCounter();</span><br><span class="line">echo $counter; <span class="comment">// 11</span></span><br><span class="line">静态变量 ( <span class="keyword">static</span> )</span><br><span class="line">静态变量在一个函数中被多次调用时，其值不会丢失，但此变量仅在函数内时可见的。</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">updateCounter</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">static</span> $counter = <span class="number">0</span>;</span><br><span class="line">    $counter++;</span><br><span class="line"></span><br><span class="line">    echo <span class="string">"Static counter is now &#123;$counter&#125;\n"</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$counter = <span class="number">10</span>;</span><br><span class="line">updateCounter(); <span class="comment">// Static counter is now 1</span></span><br><span class="line">updateCounter(); <span class="comment">// Static counter is now 2 // 不会再被付初始值</span></span><br><span class="line">echo <span class="string">"Global couter is &#123;$couter&#125;\n"</span>; <span class="comment">// Global counter is 10</span></span><br></pre></td></tr></table></figure>
<h3 id="php-时间差"><a href="#php-时间差" class="headerlink" title="php 时间差"></a>php 时间差</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">$dateTimeOne = <span class="string">'00:00:40'</span>;</span><br><span class="line">$dateTimeTwo = <span class="string">'00:00:50'</span>;</span><br><span class="line">$timeOne = explode(<span class="string">':'</span>, $dateTimeOne);</span><br><span class="line">$timeTwo = explode(<span class="string">':'</span>, $dateTimeTwo);</span><br><span class="line"></span><br><span class="line">$hour = $timeOne[<span class="number">0</span>] + $timeTwo[<span class="number">0</span>];</span><br><span class="line">$min = $timeOne[<span class="number">1</span>] + $timeTwo[<span class="number">1</span>];</span><br><span class="line">$sec = $timeOne[<span class="number">2</span>] + $timeTwo[<span class="number">2</span>];</span><br><span class="line"></span><br><span class="line">$newS = $sec / <span class="number">60</span>; <span class="comment">//得到分钟数</span></span><br><span class="line">$newS1 = $sec % <span class="number">60</span>; <span class="comment">//得到秒数</span></span><br><span class="line"></span><br><span class="line">$newM = $min / <span class="number">60</span>; <span class="comment">// 得到小时数</span></span><br><span class="line">$newM1 = $min % <span class="number">60</span>; <span class="comment">//得到分钟</span></span><br><span class="line"></span><br><span class="line">$newH = $hour / <span class="number">60</span>; <span class="comment">// 得到天数</span></span><br><span class="line">$newH1 = $hour % <span class="number">60</span>; <span class="comment">// 得到小时数</span></span><br><span class="line"></span><br><span class="line">$min = floor($newS + $newM1);</span><br><span class="line">$sec = floor($newS1);</span><br><span class="line">$hour = floor($newM + $newH1);</span><br><span class="line"></span><br><span class="line">echo $hour . <span class="string">':'</span> . $min . <span class="string">':'</span> . $sec;</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/articles/39760</span></span><br></pre></td></tr></table></figure>
<h3 id="php-fpm-502"><a href="#php-fpm-502" class="headerlink" title="php-fpm 502"></a>php-fpm 502</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">php-fpm.conf 的配置 ，静态模式，动态模式，内存模式</span><br><span class="line"><span class="number">1</span>：静态适合 大内存的，</span><br><span class="line"><span class="number">2</span>： 适合内存适合 <span class="number">4</span>g,<span class="number">2</span>g</span><br><span class="line"><span class="number">3</span>：微内存的模式 适合 <span class="number">512</span> ，<span class="number">256</span> 的内存</span><br><span class="line"></span><br><span class="line">进程数 的配置 根据 cpu 核数 和内存 / <span class="number">30</span>M 的设置 一般一个 worker 进程占 <span class="number">30</span>m 大小</span><br><span class="line"></span><br><span class="line"><span class="number">502</span> ，<span class="number">504</span> 错误处理</span><br><span class="line"><span class="number">502</span> 网关错误，php-fpm 进程无法处理 大量的请求，导致的</span><br><span class="line"><span class="number">504</span> 而是 请求过去，php-fpm 处理超时，无法返回请求导致的</span><br><span class="line">https:<span class="comment">//learnku.com/articles/39903</span></span><br></pre></td></tr></table></figure>
<h3 id="php读取大文件"><a href="#php读取大文件" class="headerlink" title="php读取大文件"></a>php读取大文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">memory_get_peak_usage();</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">formatBytes</span>(<span class="params">$bytes, $precision = <span class="number">2</span></span>) </span>&#123;</span><br><span class="line">    $units = array(<span class="string">"b"</span>, <span class="string">"kb"</span>, <span class="string">"mb"</span>, <span class="string">"gb"</span>, <span class="string">"tb"</span>);</span><br><span class="line"></span><br><span class="line">    $bytes = max($bytes, <span class="number">0</span>);</span><br><span class="line">    $pow = floor(($bytes ? log($bytes) : <span class="number">0</span>) / log(<span class="number">1024</span>));</span><br><span class="line">    $pow = min($pow, count($units) - <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">    $bytes /= (<span class="number">1</span> &lt;&lt; (<span class="number">10</span> * $pow));</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> round($bytes, $precision) . <span class="string">" "</span> . $units[$pow];</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">readTheFile</span>(<span class="params">$path</span>) </span>&#123;</span><br><span class="line">    $lines = [];</span><br><span class="line">    $handle = fopen($path, <span class="string">"r"</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span>(!feof($handle)) &#123;</span><br><span class="line">        $lines[] = trim(fgets($handle));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    fclose($handle);</span><br><span class="line">    <span class="keyword">return</span> $lines;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">readTheFile(<span class="string">"shakespeare.txt"</span>);</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">readTheFile</span>(<span class="params">$path</span>) </span>&#123;</span><br><span class="line">    $handle = fopen($path, <span class="string">"r"</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span>(!feof($handle)) &#123;</span><br><span class="line">        <span class="keyword">yield</span> trim(fgets($handle));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    fclose($handle);</span><br><span class="line">&#125;</span><br><span class="line">$zip = <span class="keyword">new</span> ZipArchive();</span><br><span class="line">$filename = <span class="string">"filters-1.zip"</span>;</span><br><span class="line"></span><br><span class="line">$zip-&gt;open($filename, <span class="attr">ZipArchive</span>::CREATE);</span><br><span class="line">$zip-&gt;addFromString(<span class="string">"shakespeare.txt"</span>, file_get_contents(<span class="string">"shakespeare.txt"</span>));</span><br><span class="line">$zip-&gt;close();</span><br><span class="line">https:<span class="comment">//learnku.com/php/t/39751</span></span><br></pre></td></tr></table></figure>
<p><a href="https://phpdocker.io/generator" target="_blank" rel="noopener">phpdocker 镜像网站</a></p>
<p><a href="http://www.siya89.com/blog/docker%20lnmp" target="_blank" rel="noopener">docker 神器之 「lnmp 环境篇」</a></p>
<p><a href="https://learnku.com/articles/39917" target="_blank" rel="noopener">PHP 学习笔记之正则表达式</a></p>
<p><a href="https://learnku.com/articles/39736" target="_blank" rel="noopener">阿里云视频点播转码</a></p>
<p><a href="https://github.com/xiaoyukarl/jd_biz" target="_blank" rel="noopener">京东大商户对接 API </a></p>
<p><a href="https://learnku.com/articles/39691" target="_blank" rel="noopener">    阿里云 OSS 上传</a></p>
<p><a href="https://mkblog.cn/690/" target="_blank" rel="noopener"> PHP 略缩图裁剪插件</a></p>
<p><a href="https://learnku.com/articles/39626" target="_blank" rel="noopener">composer自动加载原理</a></p>
<p><a href="https://github.com/thirdgerb/chatbot" target="_blank" rel="noopener">对话机器人框架 CommuneChatbot</a></p>
<p><a href="https://github.com/buqiu/arr" target="_blank" rel="noopener">数组增强组件</a></p>
<p><a href="https://github.com/mylxsw/wizard" target="_blank" rel="noopener">开源文档管理系统 Wizard</a></p>
<p><a href="https://learnku.com/articles/38855" target="_blank" rel="noopener">PhpStorm 中使用 PHP Inspections 进行代码静态分析</a></p>
<p><a href="https://cdn.learnku.com/uploads/images/201912/27/31440/JXuXebxK55.png!large" target="_blank" rel="noopener">php开发技术栈导图</a></p>
<p><a href="https://www.shanyuliang.com/archives/150" target="_blank" rel="noopener">聊天系统代码</a></p>
<p><a href="https://www.shanyuliang.com/archives/133" target="_blank" rel="noopener">php添加水印和缩略图</a></p>
<p><a href="https://github.com/justcodingnobb/app-store-scrape" target="_blank" rel="noopener">获取 AppStore 信息</a></p>
<p><a href="https://github.com/viest/php-ext-excel-export" target="_blank" rel="noopener">PHP Excel 扩展 xlswriter </a></p>
<p><a href="https://github.com/php-casbin/php-casbin" target="_blank" rel="noopener">PHP权限库支持 ACL,RBAC,ABAC 等权限控制</a></p>
<p><a href="https://github.com/jqhph/easy-excel" target="_blank" rel="noopener">Excel读写工具php excel</a></p>
<p><a href="https://learnku.com/articles/29219" target="_blank" rel="noopener">Leetcode 二叉树题目集合</a></p>
<p><a href="https://github.com/jqhph/easy-excel" target="_blank" rel="noopener">使用简单实用的语义化接口快速读写Excel文件composer </a></p>
<p><a href="https://anemone.top/php-PHP%E4%B8%AD%E7%9A%84%E5%8D%B1%E9%99%A9%E5%87%BD%E6%95%B0%E5%92%8C%E4%BC%AA%E5%8D%8F%E8%AE%AE/" target="_blank" rel="noopener">PHP中的危险函数和伪协议</a></p>
<p><a href="https://learnku.com/articles/38375#replies" target="_blank" rel="noopener">一次获取客户端 IP 记录</a></p>
<p><a href="https://github.com/zacao/php-developer-prepares" target="_blank" rel="noopener">PHP 开发者实践</a></p>
<p><a href="http://websocketd.com/" target="_blank" rel="noopener">php websocket</a></p>
<p><a href="https://www.awaimai.com/php" target="_blank" rel="noopener">PHP启示录</a></p>
<p><a href="https://github.com/doododo/ocr" target="_blank" rel="noopener">腾讯优图 OCR Composer 包</a></p>
<p><a href="https://github.com/liaoshengping/ali_open" target="_blank" rel="noopener">阿里巴巴开放平台php sdk</a></p>
<p><a href="http://doc.celerstar.com/website/soft/php-ml/" target="_blank" rel="noopener">机器学习PHP库</a></p>
<p><a href="https://www.kancloud.cn/hubqin/thinkphp/1361597" target="_blank" rel="noopener">ThinkPHP6.0 核心分析汇总</a></p>
<p><a href="http://www.shiguopeng.cn/archives/40" target="_blank" rel="noopener">PHP通过反射实现自动注入参数</a></p>
<p><a href="https://github.com/DavidNineRoc/design-pattern" target="_blank" rel="noopener">PHP中常见的设计模式</a></p>
<p><a href="https://github.com/DavidNineRoc/leet-code" target="_blank" rel="noopener">php leetCode 的学习</a></p>
<p><a href="https://learnku.com/articles/37460" target="_blank" rel="noopener">《PHP 微服务练兵》系列教程</a></p>
<p><a href="https://github.com/viest/php-ext-xlswriter" target="_blank" rel="noopener">php excel扩展</a></p>
<p><a href="https://phpartisan.cn/?keyword=laravel%E7%88%AC%E8%99%AB%E5%AE%9E%E6%88%98" target="_blank" rel="noopener">laravel guzzle爬虫</a></p>
<p><a href="https://learnku.com/articles/33451" target="_blank" rel="noopener">PHP7 的垃圾回收机制</a></p>
<p><a href="https://github.com/Hanson/weibot" target="_blank" rel="noopener">微博机器人</a></p>
<p><a href="https://bettercuicui.github.io/2018/04/01/%E6%9E%B6%E6%9E%84/%E5%A4%A7%E5%9E%8B%E7%BD%91%E7%AB%99%E6%8A%80%E6%9C%AF%E6%9E%B6%E6%9E%84/#" target="_blank" rel="noopener">大型网站技术架构</a></p>
<p><a href="https://4ark.me/post/b6c7c0a2.html" target="_blank" rel="noopener">在谷歌浏览器输入 URL 回车之后发生了什么</a></p>
<p><a href="https://www.qqdeveloper.com/2019/10/10/chaomai/" target="_blank" rel="noopener">电商秒杀超卖解决方案</a></p>
<p><a href="https://learnku.com/articles/37060" target="_blank" rel="noopener">高并发设计笔记</a></p>
<p><a href="https://doc.phpspider.org/demo-start.html" target="_blank" rel="noopener">php爬虫</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/13/有了内网穿透神器-ngrok-，个人电脑也能做服务器/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/13/有了内网穿透神器-ngrok-，个人电脑也能做服务器/" itemprop="url">有了内网穿透神器 ngrok ，个人电脑也能做服务器</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-13T19:40:10+08:00">
                2019-11-13
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.1k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  8 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>平常我们访问的网站都是由具有公网ip的服务器提供的，如果想做自己的网站也得要有个自己的服务器（当然也可以使用GitHub这种做静态网站，下次可以说说），其实服务器简单来说也就是一台电脑而已，那可不可以将自己的电脑做服务器呢？答案是可以的，这里推荐一个免费的内网穿透神器 <code>ngrok</code>，关于什么是内网穿透看百科解释：<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">内网穿透，即NAT穿透，网络连接时术语，计算机是局域网内时，</span><br><span class="line">外网与内网的计算机节点需要连接通信，映射端口能让外网的电脑找到处于内网的电脑，提高下载速度。</span><br></pre></td></tr></table></figure></p>
<p>简单来说就是通过ngrok 可以生成一个外网地址，然后找到到本地服务器就可以访问自己电脑的文件，具体如何使用ngrok内网穿透如下，非常简单。</p>
<h3 id="搭建本地服务器"><a href="#搭建本地服务器" class="headerlink" title="搭建本地服务器"></a>搭建本地服务器</h3><p>首先在自己电脑新建一个文件 index.html ，内容自己随意写了，然后搭建一个简单的服务器，可以通过ip和端口访问到这个文件。</p>
<p>比如我本机装了php，执行一行命令就可以 。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">php -S localhost:<span class="number">4000</span></span><br></pre></td></tr></table></figure></p>
<p>然后浏览器打开 localhost:4000 就能访问到本地的文件 index.html，这是一个周杰伦的个人PPT介绍，空格键翻页，和平常使用的PPT一样。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-70805f3d1c6b55ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>python 也是一样的。<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">λ python -m http.server <span class="number">4000</span></span><br><span class="line">Serving HTTP on <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span> port <span class="number">8000</span> (http:<span class="comment">//0.0.0.0:4000/) ...</span></span><br></pre></td></tr></table></figure></p>
<p>如果对命令行不熟悉直接安装个软件NGINX  <a href="https://www.nginx.com/" target="_blank" rel="noopener">https://www.nginx.com/</a> 直接启动就行。</p>
<h3 id="ngrok"><a href="#ngrok" class="headerlink" title="ngrok"></a>ngrok</h3><p> ngrok软件官网 <a href="https://dashboard.ngrok.com/get-started" target="_blank" rel="noopener">https://dashboard.ngrok.com/get-started</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-55dc4a9b78e2db98.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>我用谷歌账号直接登录，也可以自己用邮箱注册，然后copy 自己的token。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-b3a0bcc466935020.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>下载软件（对应自己的电脑系统）到本地后，在cmd命令行执行<code>ngrok authtoken 1THs9sajgDwQV1RS5ER6pc6nHo2_7gVJGSiAzT91YpAiS7f54</code><br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"># ngrok authtoken 1THs9sajgDwQV1RS5ER6pc6nHo2_7gVJGSiAzT91YpAiS7f54</span><br><span class="line">Authtoken saved to configuration file: C:\Users\xx/.ngrok2/ngrok.yml</span><br><span class="line">ngrok by @inconshreveable                                                              (Ctrl+C to quit)</span><br><span class="line"></span><br><span class="line">Session Status                online</span><br><span class="line">Account                        (Plan: Free)</span><br><span class="line">Version                       <span class="number">2.3</span><span class="number">.35</span></span><br><span class="line">Region                        United States (us)</span><br><span class="line">Web Interface                 http:<span class="comment">//127.0.0.1:4040</span></span><br><span class="line">Forwarding                    http:<span class="comment">//7ef9b347.ngrok.io -&gt; http://localhost:4000</span></span><br><span class="line">Forwarding                    https:<span class="comment">//7ef9b347.ngrok.io -&gt; http://localhost:4000</span></span><br><span class="line"></span><br><span class="line">Connections                   ttl     opn     rt1     rt5     p50     p90</span><br><span class="line">                              <span class="number">0</span>       <span class="number">0</span>       <span class="number">0.00</span>    <span class="number">0.00</span>    <span class="number">0.00</span>    <span class="number">0.00</span></span><br></pre></td></tr></table></figure></p>
<p>浏览器打开<a href="http://7ef9b347.ngrok.io" target="_blank" rel="noopener">http://7ef9b347.ngrok.io</a> 就可以打开自己电脑的文件 index.html，同样可以在命令行中可以看到访问到的文件。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-c64e89beddc0d720.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>效果如图<br><img src="https://upload-images.jianshu.io/upload_images/17817191-74ac92b008b96aff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>命令行中的 Web Interface 是 Ngrok 内置的一个管理面板，用来展示所有通过 Ngrok 进来的请求信息以及返回的数据，现在我们访问一下 <a href="http://127.0.0.1:4040" target="_blank" rel="noopener">http://127.0.0.1:4040</a> 看看。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-69b171ad5ed9e2be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>现在你有了一个自己的域名<a href="http://7ef9b347.ngrok.io" target="_blank" rel="noopener">http://7ef9b347.ngrok.io</a> ，发给别人也能访问了，不过你的电脑不能关机，是不很简单，不过这个国外服务器有点慢，可以考虑国内的ngrok.cc。</p>
<h3 id="ngrok-cc"><a href="#ngrok-cc" class="headerlink" title="ngrok.cc"></a>ngrok.cc</h3><p>用邮箱注册 <a href="https://www.ngrok.cc/user.html" target="_blank" rel="noopener">https://www.ngrok.cc/user.html</a>   ，详细教程见 <a href="http://www.ngrok.cc/_book/" target="_blank" rel="noopener">http://www.ngrok.cc/_book/</a> 这个也是免费的。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-24700a4c6aeaef09.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>购买免费版本，然后设置基本信息，如果需要可以设置需要密码访问。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-2300d3cdff1ee344.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-df98b3ee658970e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>下载对应系统的软件<a href="https://www.ngrok.cc/download.html，配置文件设置好你要的域名，比如我的susheng，Windows下直接启动文件" target="_blank" rel="noopener">https://www.ngrok.cc/download.html，配置文件设置好你要的域名，比如我的susheng，Windows下直接启动文件</a> <code>Sunny-Ngrok启动工具.bat</code> 然后输入隧道id c4237a7e0be3bdad（登录后在隧道管理中复制）<br><img src="https://upload-images.jianshu.io/upload_images/17817191-8d3abc9cfa938cc3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-d627b00a45e6fabd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>浏览器访问 <a href="http://susheng.free.idcfengye.com" target="_blank" rel="noopener">http://susheng.free.idcfengye.com</a> 就可以了，很简单吧。</p>
<p><a href="https://nat.cdjxt.net/#section-home" target="_blank" rel="noopener">https://nat.cdjxt.net/#section-home</a> 这个和 ngrok.cc 类似 ，先下载客户端，配置教程见  <a href="https://nat.cdjxt.net/#section-pricing" target="_blank" rel="noopener">https://nat.cdjxt.net/#section-pricing</a>  ，然后用邮箱直接注册<br><img src="https://upload-images.jianshu.io/upload_images/17817191-fa763483ad418530.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-0a166ed2a0b75945.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>命令行执行<code>client_windows_amd64.exe -s jp.cdjxt.net -p 5993 -k 9e9ef6b89342454f9c554d83a2a94b8e -ssl true</code>可以看到运行成功了。<br><img src="https://upload-images.jianshu.io/upload_images/17817191-7f882e0650ddf327.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-3f69052735fff028.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>浏览器访问 <a href="https://m30059.jp.cdjxt.net/#/start" target="_blank" rel="noopener">https://m30059.jp.cdjxt.net/#/start</a>   看效果。</p>
<p>如果嫌装客户端麻烦，可以直接使用这个serveo</p>
<h3 id="serveo"><a href="#serveo" class="headerlink" title="serveo"></a>serveo</h3><p><a href="https://serveo.net/" target="_blank" rel="noopener">https://serveo.net/</a> 只要在命令行执行一行命令（需要先安装ssh命令，可以直接装一个git bash就行）<br><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ssh -R <span class="number">80</span>:localhost:<span class="number">4000</span> serveo.net</span><br><span class="line">Forwarding HTTP traffic <span class="keyword">from</span> https:<span class="comment">//habeo.serveo.net</span></span><br><span class="line">Press g to start a GUI session and ctrl-c to quit.</span><br></pre></td></tr></table></figure></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-98a2063b489f779f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>浏览器访问  <a href="https://habeo.serveo.net" target="_blank" rel="noopener">https://habeo.serveo.net</a> 就能访问到自己电脑的文件了。</p>
<p>现在有了内网穿透你出门在外也可以访问到自己电脑上的文件了（当然你的电脑不能关机），如果还是嫌内网穿透麻烦，还不稳定，还是建议买个自己的服务器，这里推荐下腾讯云的，一年只要88 <a href="https://cloud.tencent.com/act/double11" target="_blank" rel="noopener">https://cloud.tencent.com/act/double11</a> ，昨天双十一我刚买了一台（如果是老用户，用一个新微信注册绑定同一个身份证就行），非广告，腾讯也没给我广告费。</p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-2b7df113abb196e7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-e5a622655bb1922c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-9a67f90418917111.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br><img src="https://upload-images.jianshu.io/upload_images/17817191-1f48e99a548ce581.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"></p>
<p>推荐阅读:</p>
<p><a href="https://mp.weixin.qq.com/s/Xz1m-mqtCcBF_4hmGCpkUQ" target="_blank" rel="noopener">如何发一条空白的朋友圈</a></p>
<p><a href="https://mp.weixin.qq.com/s/NYrs5cluZgjvm85MXmiaKA" target="_blank" rel="noopener">那些在国内还能使用的谷歌产品</a></p>
<p><a href="https://mp.weixin.qq.com/s/eGDO0Y8el_dsEyriCoAgog" target="_blank" rel="noopener">那些你可能不知道的微信奇技淫巧</a></p>
<p><a href="https://mp.weixin.qq.com/s/k5lBwiDzGgSU3fh2v2Rw9A" target="_blank" rel="noopener">如何在豆瓣租房小组快速找到满意的房子</a></p>
<p><a href="https://mp.weixin.qq.com/s/iL6WyI-TChtjZMuu5G5W8A" target="_blank" rel="noopener">公众号苏生不惑原创文章整理</a></p>
<p><a href="https://mp.weixin.qq.com/s/RWxn4_Qg_Z3bL4wKusndKA" target="_blank" rel="noopener">不会写Python代码如何抓取豆瓣电影 Top 250</a></p>
<p><a href="https://mp.weixin.qq.com/s/whcZis69KnIzEUVMtrjdmA" target="_blank" rel="noopener">Python 词云分析周杰伦新歌《说好不哭》</a></p>
<p><a href="https://mp.weixin.qq.com/s/LKDGKWi62J5Zyzh3rB-IiQ" target="_blank" rel="noopener">跟随时光机回到过去看看 2005 年的百度/腾讯/淘宝/谷歌</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/17817191-8ff6e00de5b0726e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="免费星球"></p>
<h3 id="公众号：苏生不惑"><a href="#公众号：苏生不惑" class="headerlink" title="公众号：苏生不惑"></a>公众号：苏生不惑</h3><p> <img src="https://upload-images.jianshu.io/upload_images/17817191-6e0079f95d4c0338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="扫描二维码关注或搜索微信susheng_buhuo"></p>
<h3 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h3><p>Mac 安装使用 Ngrok <a href="https://learnku.com/articles/36129" target="_blank" rel="noopener">https://learnku.com/articles/36129</a><br>内网穿透神器 Ngrok 的使用<a href="https://learnku.com/articles/36003" target="_blank" rel="noopener">https://learnku.com/articles/36003</a><br><a href="https://www.jianshu.com/p/33d0a8f77961" target="_blank" rel="noopener">https://www.jianshu.com/p/33d0a8f77961</a><br><a href="https://www.cpolar.com/" target="_blank" rel="noopener">https://www.cpolar.com/</a><br><a href="https://learnku.com/articles/36129#reply116370" target="_blank" rel="noopener">https://learnku.com/articles/36129#reply116370</a><br>可以实现内网穿透的几款工具<a href="https://my.oschina.net/ZL520/blog/2086061" target="_blank" rel="noopener">https://my.oschina.net/ZL520/blog/2086061</a><br>Ngrok Natapp 小米球 Sunny-Ngrok echosite Ssh、autossh Lanproxy Spike frp fcn 花生壳<br>内网穿透多款工具测试 <a href="https://hacpai.com/article/1568482350815" target="_blank" rel="noopener">https://hacpai.com/article/1568482350815</a><br>内网穿透工具浅评 <a href="https://www.v2ex.com/t/575865" target="_blank" rel="noopener">https://www.v2ex.com/t/575865</a><br>smarGate： <a href="https://github.com/lazy-luo/smarGate" target="_blank" rel="noopener">https://github.com/lazy-luo/smarGate</a><br>Frp： <a href="https://github.com/fatedier/frp" target="_blank" rel="noopener">https://github.com/fatedier/frp</a><br>Ngrok： <a href="https://github.com/inconshreveable/ngrok" target="_blank" rel="noopener">https://github.com/inconshreveable/ngrok</a><br><a href="https://github.com/cnlh/nps/" target="_blank" rel="noopener">https://github.com/cnlh/nps/</a><br>有哪些简单实用的端口映射（内网穿透）软件工具？<a href="https://www.zhihu.com/question/49629610" target="_blank" rel="noopener">https://www.zhihu.com/question/49629610</a><br><a href="https://qydev.com/download.html" target="_blank" rel="noopener">https://qydev.com/download.html</a> ngork <a href="http://help.qydev.com/1242213" target="_blank" rel="noopener">http://help.qydev.com/1242213</a><br>量子互联<a href="https://www.nsloop.com/" target="_blank" rel="noopener">https://www.nsloop.com/</a><br>内网穿透新章法 serveo<a href="https://hacpai.com/article/1564394400425" target="_blank" rel="noopener">https://hacpai.com/article/1564394400425</a><br><a href="https://www.moerats.com/Aria2/#!/downloading" target="_blank" rel="noopener">https://www.moerats.com/Aria2/#!/downloading</a><br><a href="https://hacpai.com/article/1568482350815" target="_blank" rel="noopener">https://hacpai.com/article/1568482350815</a>   <a href="https://cloud.tencent.com/developer/article/1507091" target="_blank" rel="noopener">https://cloud.tencent.com/developer/article/1507091</a><br><a href="https://github.com/fatedier/frp/blob/master/README_zh.md" target="_blank" rel="noopener">https://github.com/fatedier/frp/blob/master/README_zh.md</a><br>frp <a href="https://www.hi-linux.com/posts/25686.html" target="_blank" rel="noopener">https://www.hi-linux.com/posts/25686.html</a>  <a href="https://natapp.cn/" target="_blank" rel="noopener">https://natapp.cn/</a><br><a href="https://github.com/ffay/lanproxy" target="_blank" rel="noopener">https://github.com/ffay/lanproxy</a><br><a href="https://juejin.im/post/5cad5e675188251b1b2f5517" target="_blank" rel="noopener">https://juejin.im/post/5cad5e675188251b1b2f5517</a><br><a href="https://manager.xiaomiqiu.com/index" target="_blank" rel="noopener">https://manager.xiaomiqiu.com/index</a><br><img src="https://upload-images.jianshu.io/upload_images/17817191-3d3d7b3fb0e68d0d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="image.png"><br>如果没有服务器的话推荐个免费的 <a href="https://www.natfrp.com/" target="_blank" rel="noopener">https://www.natfrp.com/</a><br>内网穿透工具(替代 ngrok 和花生壳) <a href="https://github.com/longshengwang/tcpthrough-server" target="_blank" rel="noopener">https://github.com/longshengwang/tcpthrough-server</a><br>FCN 一键免费穿透，日常维护管理基本够用了<a href="https://cn.v2ex.com/t/617484#reply86" target="_blank" rel="noopener">https://cn.v2ex.com/t/617484#reply86</a><br> ssh -R 20001:localhost:80 <a href="mailto:root@a.a.a.a" target="_blank" rel="noopener">root@a.a.a.a</a> 或者 autossh -p22 -M 5000 -NR 20001:0.0.0.0:80 <a href="mailto:root@a.a.a.a" target="_blank" rel="noopener">root@a.a.a.a</a>，autossh 会一直尝试重新连接 可以消除网络故障隐患，ssh 透传的缺陷是透传到外网的端口只能监听 127<br> zerotier，非常好用的内网穿透方案，可以把多个内网机器组一个局域网，然后使用一个有公网IP的机器或者vps做中转节点(moon)进行加速，这样就把多个内网机器+一个公网机器组成了一个本地局域网: <a href="https://jiajunhuang.com/sharing#250" target="_blank" rel="noopener">https://jiajunhuang.com/sharing#250</a> 亲爱的小伙伴：<br> <a href="https://www.cnblogs.com/along21/p/8384304.html" target="_blank" rel="noopener">超好用内网映射神器</a><br> 免费的内网穿透服务，轻松在自家电脑搭建网站 <a href="https://www.natfrp.com/" target="_blank" rel="noopener">https://www.natfrp.com/</a><br>十分钟快速搭建内网穿透工具 —— frp <a href="https://gleehub.com/tool/%E5%8D%81%E5%88%86%E9%92%9F%E5%BF%AB%E9%80%9F%E6%90%AD%E5%BB%BA%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E5%B7%A5%E5%85%B7%20%E2%80%94%E2%80%94%20frp.html" target="_blank" rel="noopener">https://gleehub.com/tool/%E5%8D%81%E5%88%86%E9%92%9F%E5%BF%AB%E9%80%9F%E6%90%AD%E5%BB%BA%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E5%B7%A5%E5%85%B7%20%E2%80%94%E2%80%94%20frp.html</a><br>( <a href="https://www.natfrp.org/" target="_blank" rel="noopener">https://www.natfrp.org/</a>) 是一个免费的内网穿透平台<br>Frp内网穿透<a href="https://www.yangchong.top/2019/03/13/Frp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" target="_blank" rel="noopener">https://www.yangchong.top/2019/03/13/Frp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/</a><br>nps是一款轻量级、高性能、功能强大的内网穿透代理服务器。目前支持tcp、udp流量转发 <a href="https://github.com/cnlh/nps" target="_blank" rel="noopener">https://github.com/cnlh/nps</a><br>内网穿透 <a href="https://github.com/txthinking/mr2" target="_blank" rel="noopener">https://github.com/txthinking/mr2</a><br>Fcn 傻瓜式内网穿透软件<br><a href="https://github.com/boywhp/fcn" target="_blank" rel="noopener">https://github.com/boywhp/fcn</a>  <a href="https://syncthing.net/" target="_blank" rel="noopener">https://syncthing.net/</a><br><a href="https://github.com/ssstk/cngrok" target="_blank" rel="noopener">https://github.com/ssstk/cngrok</a><br>比 frp 更好用的内网穿透工具 nps<a href="https://github.com/cnlh/nps" target="_blank" rel="noopener">https://github.com/cnlh/nps</a>  <a href="https://github.com/KunTengRom/xfrp" target="_blank" rel="noopener">https://github.com/KunTengRom/xfrp</a> <a href="https://nps.hanxi.info/login/register" target="_blank" rel="noopener">https://nps.hanxi.info/login/register</a> frp 也有人写了面板 <a href="https://www.natfrp.org/" target="_blank" rel="noopener">https://www.natfrp.org/</a><br>nps<br><a href="http://nav.xiejiahe.com/#/index?page=3" target="_blank" rel="noopener">http://nav.xiejiahe.com/#/index?page=3</a><br>我安利一个比较偏门，偏开发者的应用，内网穿透，<a href="http://www.notr.tech" target="_blank" rel="noopener">http://www.notr.tech</a> 。一条命令搞定。</p>
<p>内置免费 mr2 服务器, 将本地服务器暴露在外网 npm install -g @txthinking/mr2 <a href="https://www.v2ex.com/t/568236#reply25" target="_blank" rel="noopener">https://www.v2ex.com/t/568236#reply25</a> <a href="https://github.com/txthinking/mr2" target="_blank" rel="noopener">https://github.com/txthinking/mr2</a></p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/23/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/23/">23</a><span class="page-number current">24</span><a class="page-number" href="/page/25/">25</a><span class="space">&hellip;</span><a class="page-number" href="/page/39/">39</a><a class="extend next" rel="next" href="/page/25/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
